Divzeros

From Esolang
Jump to navigation Jump to 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.

You can make a string by putting quotation marks around it. This string can only be used as a parameter for a function call. The code fn("abC") will expand to (fn('a)+fn('b)+fn('C))

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 }}

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
}}

Beer program (using UNIX newline):

Amount=99;
Print=?@;
Equal=1-(1&(@~@));
BottlesOfBeer=Print(" bottles of beer");
OnTheWall=Print(" on the wall")+?10;
Current=Amount()-#;
PrintNumber=(@/10)*?('0+(@/10))+?('0+(@%10));
NoMore=Equal(Current()-1)*(Print("No more bottles of beer on the wall")/0);
Line1=PrintNumber(Current())+BottlesOfBeer()+OnTheWall();
Line2=PrintNumber(Current())+BottlesOfBeer()+?10;
Line3=Print("Take 1 down and pass it around")+?10;
Line4=NoMore()+PrintNumber(Current()-1)+BottlesOfBeer()+OnTheWall();
Iteration=Line1()+Line2()+Line3()+Line4()+?10;
Iteration()

External resources