Notes on the word tree

The beginning

This programming language makes use of «words». The word abs, for example, is a word with one argument, and its result is the absolute value of that argument.

abs -5 = 5.

Here are two two other words: sum and prod, which both take exactly two arguments. This time, the first argument is not just a number, but another word applied to other numbers. We use the word term to refer to anything that can be an argument. (prod 2 3) is a term within the term (sum prod 2 3 4).

sum prod 2 3 4 = sum (prod 2 3) 4 = sum 6 4 = 10.

Every word has an arity: the amount of arguments it takes. Word with arity of 1, like abs, are called unary, and those like sum and prod are called binary.

abs 1 2 = sum 4 = prod 1 2 3 = undefined.

Here is a term that takes 5 and gives 5+4:

W 5 sum 4 S = sum 4 S : 5 = sum (4 : 5) (S : 5) = sum 4 5 = 9.

Let me explain: every word, along with its specified arguments, has one hidden, implicit argument. sum, like most words, passes its implicit argument to each of its explicit arguments. We write the value of the implicit argument after the colon. The word 4, like any other number, discards the argument and only gives its own value. The word S, on the other hand, gives the value of the implicit argument. The binary word W passes its first argument as an implicit argument to the its second argument.

This was the hardest part. If that paragraph was overwhelming, sorry. I make this language up while writing this. I'm also seeing familiar ideas: the syntax we ended up with is just postfix expressions; every term is given an "environment" during evaluation; and special words, almost like combinators, modify that environment.

The end

This is the part where i run out of energy to show uses for this system and instead flash you with notes for how this idea develops. If you recognise established combinators, note that i don't understand combinators and you'd be better at this programming language than me. Just keep in mind that currying doesn't exist in this language, at least on the syntax level.

The word C for chain applies argument 1 to the result of argument 2:

C mul S 2 sum S 1 : 3 = mul S 2 : (sum S 1 : 3) = mul S 2 : 4 = 8.

If there was a conditional construct, it would probably look like this: U condition if-yeah if-nah.

If there were lists made of cons cells, cdar = C T S H S, where H is for head and T is for tail.

Program syntax

A program would be a sequence of definitions, each consisting of a name, a number for arity and the meaning.

program = {definition};
definition = "D" name number term.

I have this idea of building an environment, where in the beginning of a program the interpreter sets up an empty list, and upon encounter with every let-definition, reserves a spot in the list and defines an accessor for that spot.

deintion = "D" name number term | "L" name.