Lambda Calculus Primer

From Esolang
Jump to navigation Jump to search

Lambda Calculus Primer is an esolang created by User:LarhoCherqi. It comprises of only four characters (any other characters are not parsed). Given how simple this is, I am very confident that a concept similar to this already exists.

Terminology

The storage system (what this article will call memory past this point) of Lambda Calculus Primer is a set (this article calls them sets but they're not sets, think of them more as arrays). Each element of the set can either be a set itself or a lambda. Lambdas are an instruction or a group of instructions that are stored in memory.

Locations

In almost all instructions, a location is at play. A location is an index to a specific set in the memory. Locations in the context of programs are written as so:

  • The starting memory set ([])'s location would be nothing. Everything in memory resides in this set.
  • If there were to be a set inside of the starting set, that set's location would be []. For any additional elements, you add one extra [] to the location, so something at the second element of the main set's location would be [][].
  • To get a location for a set inside one of those sets, first get the location of the parent set, then treat that set as the new "starting set". Next, place the relative location of the child set inside the brackets of the parent set. Repeat this process until you have reached the set you are looking for.

An example of this will be demonstrated using Python list indices. If the memory is a list, then an element at memory[2][1][0] would have a location of [][][[][[]]].

Instructions

The spaces in the syntax are not required, they are just there for clarity.

Period

The . character, when used as a command, can append or remove elements from any given set. An "element" can be either a set structure or a lambda. The syntax for . is the following:

. item . location .

item is the element is being appended. location is what set the element gets appended to.

If item is nothing, the item at location is removed instead.

Slash

The / character, when used as a command, can retrieve data from memory and return it to other commands. It can alternatively execute code. The syntax for / is the following:

/ location .

location is where to get data from.

When an extra / is placed next to the existing one, it will execute the lambda stored at location.

Brackets

When brackets are used as a command, the syntax is the following:

[ check ] true . false .

If the set at the location check is the empty set (if there are no elements in it), run the lambda at the location true. If not, run the lambda at the location false. Both true and false can be nothing.

Brackets (alternative use)

When check is nothing, the data at the memory location true is interpreted as a number and printed out. false is what mode to use when printing (the mode can either be [] or nothing at all). A number is represented by having a set contain x sets inside of it, with x being the number that's represented. If false is [], the ASCII character that corresponds to the number gets printed instead.