Commlang

From Esolang
Jump to navigation Jump to search

Commlang was an attempt by User:Monochromeninja to create a community-based esolang, but ended up doing it their own way.

Commlang uses a single stack of integers. EOF is -1, empty stack is repeated 0, and stack indices are 0-based, where negative indices start at the bottom.

Commands

Commlang has the following commands. Either the shorthand or verbose form may be used for each command.

Shorthand command Verbose command Description
{N} push N Push N to the stack.
! pop Pop the top of the stack.
` del Pop X, then delete the X'th item of the stack. (! and {0}` are equivalent)
: dup Duplicate the top of stack.
_ in Push a single character of input, converted to its codepoint.
" out Pop X, interpret it as a codepoint, then output it.
+ add Pop A, pop B, push B + A.
- sub Pop A, pop B, push B - A.
* mul Pop A, pop B, push B * A.
/ div Pop A, pop B, push B / A rounded down.
% mod Pop A, pop B, push B % A.
~ neg Pop X, push -X.
= eq Pop A, pop B, push 1 if B == A, else 0.
< less Pop A, pop B, push 1 if B < A, else 0.
@ swap Swap the top two elements of the stack.
[F] [F] Push function F to the stack.
^ call Pop function F and insert its code immediately after the ^.
. comp Pop function F, pop function G, push the function that consists of G's code concatenated with F's code.
$ pick Pop X, then copy the X'th item of the stack to the top. (: and {0}$ are equivalent)
? rand Pop X, then push a random integer between 0 and X inclusive.
# debug Toggle debug info. (interpreter-specific)

Examples

Cat program:

[:{2}${1}~=[{2}$_{2}`@!@:^]@[]@`^]:^!!![:{2}${0}=[{1}~$"{1}~`^]@[]@`^]:^

In verbose form:

[
 dup
 push 2 pick
 push 1 neg eq
 [
  push 2 pick
  input
  push 2 del
  swap pop swap
  dup call
 ]
 swap
 []
 swap
 del call
]
dup call
pop pop pop
[
 dup
 push 2 pick
 push 0 eq
 [
 push 1 neg
 pick out
 push 1 neg del
 call
 ]
 swap
 []
 swap
 del call
]
dup call

Infinite loop:

[:^]:^

In verbose form:

[
 dup call
]
dup call

External resources