MSP with eval/apply
MSPea is an extension of MSP with an eval and apply that enables execution of arbitrary code.
Additional instructions
compile extfocus
- Compiles the string selected by
extfcous
into a molecule and assigns it toextfcous
. It is capable of compiling strings representing programs in the primitive instruction set PGLA with MSP as basic instruction set.
Returnsfalse
when there are errors detected. apply extfocus
- If
extfocus
is a string, it is executed as a basic instruction and returns the value returned by the basic instruction. It fails otherwise. eval extfocus
- If
extfocus
is a string, it compiles the string into a molecule, after which the molecule is evaluated. Ifextfocus
is an atom, it is evaluated. It fails otherwise.
The returned value ofeval
is the returned value of the last evaluated basic instruction.
Molecular representation of code
Compilation results in a molecule that represents a null-terminated list of instructions connected bynext
fields.
The instructions are represented by an atom with additional fields.
The possible instructions are:
- end
- This instruction consists of an atom with an
end
field, and stops the evaluation. - goto
- Consists of an atom with a
goto
field which selects the next instruction to be evaluated. - test
- Consists of an atom with the fields
test
,basic
,T
, andF
. On the returned value of the basic instruction, selected by thebasic
field, either theT
(true) or theF
(false) field selects the next instruction to be evaluated. - basic
- Consists of an atom with the field
basic
which selects a basic instructions to be evaluated. Evaluation continues with the next instruction in the list.
false
is returned as the result of this instruction.
Example
The following program counts until 10 and then stops.x = 0; incr x; + x == 10; !; \\#3
This can be put in a string and assigned to a focus with the instruction
count = "x = 0; incr x; + x == 10; !; \\\\#3"
Compilation of count
results in the molecule
