Funcinton

From Esolang
Jump to navigation Jump to search

Not to be confused with Funciton.

Funcinton is an esolang designed User:Monochromeninja to be able to use integers as functions and vice versa.

There is one stack that starts empty. Indexing out of bounds gives a 0.

Integer-function interchanging

The integer 0 is treated as an empty string. Any other integer n is treated as the function of the integer n//256 (where // means integer division) concatenated with the ASCII character with the codepoint of n%256 (where % means modulus). Concisely:

func(0) = ""
func(n) = func(n//256) + chr(n%256)

where chr(n) is the ASCII character with the codepoint of n.

Commands

  • Any digit pushes itself to the stack.
  • {N} pushes N (a multi-digit number) to the stack.
  • ? pops N and pushes a random integer R such that 0 <= R <= N.
  • Any of +-*/% pops Y, pops X, then pushes X OP Y. (/ is integer division; % is modulus.)
  • > pops Y, pops X, then pushes 1 if X > Y else 0.
  • @ pops N, then pushes a duplicate of the N'th element of the stack. (0@ duplicates the top element of the stack.)
  • ! pops N, then pops the N'th element of the stack. (0! pops the top element of the stack.)
  • _ pushes the codepoint of one character of input. (EOF is repeated -1.)
  • . pops a codepoint and outputs it as a character.
  • ^ pops a function F and runs it by inserting its code immediately after this instruction.
  • # pops F, T, and C in that order, then runs T if C is nonzero, otherwise runs F.

Examples

Cat program

{8292086038218679469791840846639459376902179}0@^

Output stack

{1207624538945969667811301018820615670734492809758244679715}0@^

This can be trivially modified to output "Hello, world!" or any fixed string. (This does not reverse the stack.)

External resources