InterWater

From Esolang
Jump to: navigation, search

InterWater is something like a combination of Unlambda and Hargfak. The syntax is different inside and outside of a code-block.

Inside of a code-block

It works like Hargfak, with all of those commands except =~|`'% and the preprocessor works like in Hargfak, except that macros are not defined inside of a code-block (they still may be called from inside of a code-block). There is also a new data type, a function (which acts similarly to a code-block, and a function code-block is a code-block).

This is how a function data-type acts:

  • +- The function does not change.
  • [] Treated as zero (unless it is a non-empty code-block).
  • . Applies the function to the memory-state (the memory-state consists of the memory, main-pointer, sub-pointer, and stack). If the result is a memory-state, then it replaces the current memory-state with the returned state, if it isn't a memory-state, then it changes the value at this memory location to the return value.

There is also some new commands:

  • ~ If the code-block was called from outside of a code-block and the top of the stack contains a function, then it will exit the code-block similar to the @ command, but instead of returning the new memory-state, it returns the function that was at the top of the stack.
  • % If the top 2 values of stack are functions, it applies the top one to the one underneath it, and replaces them with the returned function.
  • = If the top entry of the stack is a memory-state, then it replaces the current memory-state with that one instead.

Outside of a code-block

This is similar to unlambda. The commands are:

  • ` Applies a function. (works like ` in unlambda)
  • < K combinator function.
  • $ S combinator function.
  • - I combinator function.
  • > Iota combinator function.
  • ' Creates a blank memory-state (all zero, empty stack, main and sub pointer to same location).
  • {} Creates a code-block.
  • "" With text between "" it creates a blank memory-state but the stack has the first character of the string on top, the last character of the string on the bottom.
  • ! This function takes one argument, and returns a memory-state with the argument function as the only entry on the stack (the memory-state is otherwise blank).
  • # Works like the d command in unlambda.
  • () Put zero or more functions between the parentheses, separated by semicolons. Stuff inside of the paremtheses are not evaluated right away. It creates a memory-state which is blank, except that each cell starting at the main pointer and going right, contains one of the items inside this list. The sub-pointer is on the cell directly after the last item of the list.
  • ^ Call with current continuation. (works like c in unlambda)

If a code-block is applied to a memory-state, the code-block is executed with that memory-state and returns the new memory-state. If a code-block is applied to a non-memory-state, it acts as applied to what it would be if ! was applied to the argument function.

If a memory-state is applied to a memory-state, it returns a memory state which is a copy of the first one, but the contents of the stack of the second one is added onto the top of the stack of the first one. If a memory-state is applied to a non-memory-state, it returns the memory-state itself.

The preprocessor is also a bit different:

  • ?name{data} Define a inside-code-block macro (case sensitive!). If used outside of a code-block, it is replaced with the code-block in {}
  • ?name|data| Define a outside-code-block macro (case sensitive!). Cannot be used inside of a code-block.
  • name Use macro
  • number indicated a church integer function.
  • // Comment until end of line
  • ??"file" Loads a include file. It works similarly to the PATH variable in UNIX.

Examples

Macro to print string:

?print{:[.#::]}
`print "Hello, World!"

More macros to deal with strings:

?print{:[.#::]}
?concat|``$`<`$-<|
?chr|``$`<{;#:}``$``$-`<{+}`<'|
?reverse{:[>:]<[<]>[;#:>]}