Gregor's Answer
- This is still a work in progress. It may be changed in the future.
Gregor's Answer is an unfinished esoteric programming language created by Tanner Swett in 2013.
Syntax
<inner-block> ::= [whitespace] {<statement> whitespace} [<final-statement>] [whitespace] <statement> ::= <L-var> <R-var> <R-var> | <L-var> <outer-block> | <L-var> "(" <R-var> ")" <outer-block> <final-statement> ::= <statement> | <R-var> <L-var> ::= letter <R-var> ::= letter | "!" | "@"
In the above, "whitespace" means one or more whitespace characters, and "letter" means a lowercase English letter. Whitespace cannot occur where it is not expressly permitted.
Operation
Objects in Gregor's Answer have one method (which is a sequence of statements) and 26 instance variables, one denoted by each letter of the English alphabet. Each instance variable contains a reference, which points to an object, a job, or nothing. When an object is created, all of its instance variables contain references to nothing. References are mutable; a reference pointing to a job can mutate to point to anything else. Within an object's method, !
denotes a reference to the object ("self"), @
denotes the method's current argument, and each lowercase letter of the English alphabet denotes the corresponding instance variable.
The statement xyz
creates a new pending job whose target reference is y
and whose argument is z
. (The target reference and the argument are determined at the time the job is created, not at the time it runs.) x
then becomes a reference to the new job. The new job is eligible to execute whenever its target reference points to an object. When the new job is executed, its target object's method is executed ("target object" meaning the object that the target reference points to).
The statement x{...}
creates a new object whose method is ...
. x
then becomes a reference to the new object.
The statement x(y){...}
creates a new pending job. x
then becomes a reference to the new job. The new job also has a forced reference, which is y
. The new job is eligible to execute whenever y
points to an object. When the new job is executed, ...
is executed, with letters denoting the same instance variables as in the surrounding code, and !
and @
denoting the same references. (This means that the new job can modify the object's instance variables.)
Finally, the statement x
, which can only legally appear as the last statement in an inner block, causes all references which point to the current job to mutate to point to the referent of x
.
Initially, there is exactly one job, which is eligible to execute. When this job is executed, the program's source code is executed. The operation of a program is as follows: An unspecified pending job which is eligible to execute is selected. This job ceases to be pending, and is executed. This repeats until there are no pending jobs that are eligible to execute.