Divzeros

From Esolang

Jump to: navigation, search

Divzeros program is in a format with function definitions name = expression and a semicolon, the last entry is the main program, without a name and equal sign. The function name can contain uppercase/lowercase letters, period, comma, and numbers, but it cannot start with a number.

The program is in the form of a expression, using these operators (listed from high priority to low priority):

(x)   This is a parentheses for grouping expressions.
?x    Output the character x and returns x.
?     Input a character and return its ASCII number.
#x    Returns what the return value was of the x-1 iteration of the current
      subprogram. If x-1 is negative it returns the last return value of the 
      parent subprogram, if x is too large the subprogram quits.
#     Returns the number of the iteration of the current subprogram. First
      iteration is number zero.
<x    Returns left half unmingle of x.
>x    Returns right half unmingle of x.
_x    Returns x times negative one.
!x    Returns bitwise NOT x.
@     Returns parameter given to this function.
x*y
 x/y
  x%y Returns x times/divide/modulo y. If x is zero it will not evaluate y, and
      if y is zero in division or modulo function, the subprogram quits. The
      division is integer division rounded toward negative infinity.
x+y
 x-y  Returns x plus or minus y.
x&y   Returns bitwise x AND y. Does not evaluate y if x is zero.
x^y   Returns bitwise x XOR y.
x|y   Returns bitwise x OR y. Does not evaluate y if x is negative one.
x$y   Returns x mingle y (as in INTERCAL). If one of them is negative and one
      is non-negative, then y will be bitwise NOT before evaluation, to make
      both the same sign.
x~y   Returns x select y (as in INTERCAL). If x is zero it will not evaluate y.
[x]   Executes a subprogram in a loop. Returns the last return value of the
      subprogram expression before it quit.

Numbers can be integers only, and can be written in decimal, or in hex with ` at front, or as a character ' and the character to get the ASCII value of.

Functions are invoked by indicating the name of the function followed by the parameter to give to the function.

Comments can be written by putting text between {{ and }}

[edit] Examples

To copy input to output forever:

??

To copy input to output until a null character is received (and output the null character as well):

1/??

To copy input to output until a null character is received (but omit the null character from the output):

(#/?##)*0+?

Hello world program:

(?'H+?'e+?'l+?'l+?'o+?',+?' +?'W+?'o+?'r+?'l+?'d+?'!)/0

To compare if 2 numbers equal:

Equal=1-(1&(@~@));
{{
 You can call it like: Equal(x-y)
 The result will be 0 if not equal, 1 if is equal
}}

Check if x is less than y:

Less=1-[(#*#(1-@)/(2-#))*0+#];
{{
 You can call it like: Less(x-y)
 The result will be 0 if x>=y, 1 if x<y
}}
Personal tools