ערימה

From Esolang
Jump to navigation Jump to search

ערימה, ("heap" in Hebrew) is a Stack-based, functional, and self-modifying esolang made by Jussef Swissen. Its entire command set is in hebrew. I spent too much time on this language, I actually had to learn a bit of Hebrew. It was worth it however.

Specification

There are 9 commands in ערימה, and, as specified before, they are all in Hebrew. The commands are used mainly for control flow.

Command Function
החוצה -> [x] Prints x, where x is a variable holding the value you want printed.
להשתנות (x)->(y)->(z) Stores value x in variable y, which is stored in register z
שיטה [x:y:z] -> ... Declares a function with name x, return type y, z arguments.
אם [x] -> ... ח Declares if statement with condition x. ח is used to end the statement.
לדחוף -> (x) Pushes x onto stack
כבוי Pops value at top of stack
תהפכו Switch value at the top of the stack with the value below it.
רקורסיבי x ... ח Declares loops with name x. ח ends the loop.
המניה (x -> y) Stores value x in register y.

The Stack

The stack in this language operates just like a normal stack. However, the stack in ערימה is twisted and tangled, in order for data held in it to randomly switch variable names and registers. This leads all programs to be nondeterministic (but thankfully not probabilistic). The normal operations, לדחוף (push), and כבוי (pop), can be performed on the stack along with an extension, תהפכו (flip) that switches the top value on the stack with the value below it. Here is an example using these commands.

    
3 לדחוף
4 לדחוף
תהפכו

This program pushes 3 to the top of the stack, and then pushes 4 to the top of the stack. Now 4 is at the top, and 3 is below it. The flip command is used to switch the places of these elements, so that 3 is on top, and 4 is below it instead. Notice how the order in which the code is placed is reversed. This is a feature of the language that makes the code resemble Hebrew more. The commands are read from right to left, just like in actual Hebrew. However, during execution, the values could switch registers, due to the twisted stack.

Registers & Variables

Registers and variables, (המניה & להשתנות, respectively), are affected by the nondeterministic nature of this language, and are the basis for most of the other commands. There are 32 registers, a0 to a15 and b0 to b15. These 32 registers are general purpose. Variables are just values given to user defined names which are in turn stored in a specified register. If all the registers are used up, then the register can be overwritten by putting a new value in it. Here is an example using registers and variables.

(a0)<-(register0)<-(3) המניה
(a1 <- 69) להשתנות

This program stores the value 3 in variable register0. Then, the variable is stored in the register a0. It then stores value 69 in register a1.

Print

The print command, החוצה. Anything printed in this language has to be stored in a variable first. This way, the things being printed are also affected by the nondeterministic nature of ערימה. In order to use the command, a variable containing the value you want printed needs to be declared first, followed by the variable and the print command itself. Here is an example using the print command.

(b0)<-(RegB0)<-("This language is awesome!") החוצה
[RegB0] <- החוצה

This program stores the string value "This language is awesome!" in variable RegB0, which is stored in register b0. The variable is then printed, which outputs, "This language is awesome!". However, it may need to be run a few times to eventually arrive at this output.

If Statements and Loops

The if statement, אם, and the loop, רקורסיבי. Thesee are used for condition checking. The if statement must be followed by a condition , the body, and the end key word, , after its declaration. The loop, when declared must be followed by the loop name, it's body, and finally, it's end keyword, ח. Here is an example using both of these features.

(a5)<-(OneUp)<-(1) המניה
TestLoop רקורסיבי
  [OneUp] <- החוצה
  OneUp+1
  <- [!OneUp,70] אם  
      TestLoop 
      ח
ח

This program declares a variable, OneUp, with value 1. Then, it declares a loop with the name TestLoop. The loop prints OneUp, increments it, and then checks if OneUP doesn't equal 69. If it doesn't, it goes back to the top of the loop and tries again. If not, then the program automatically halts the loop. This program prints numbers 1 to 70.

Functions

Functions, שיטה, are used to simplify repetitive mechanisms. A function, when declared, need to be followed by its name, return type, arguments, and the end key word, Here is a function example.

[(a0)<-(R)המניה:int:Func] שיטה
    (a1)<-(W)<-(R+1) המניה
ח
[Func 68] <- החוצה

This program declares the function with name, Func, which returns an integer value, and has one argument. It returns R + 1. This function, with argument 68, is then printed, which will actually print 69.

Hello World Program

(b9) <- (HW) <- ("Hello, world!") החוצה
[HW] <- החוצה

Computational Properties

ערימה is Turing complete, as it can enter an Infinite loop and it has unbounded storage, despite the fact that the stack is twisted.