Runtime evaluation: Difference between revisions

Line 573:
<lang smalltalk>e := '[ :x :y | (x*x + (y*y)) sqrt ]'.
Transcript show: ((Compiler evaluate: e) value: 3 value: 4).</lang>
 
 
=={{header|SNOBOL4}}==
 
The built in function eval() evaluates SNOBOL4 expressions and returns the value. The expression is evaluated in the current environment and has access to then-current variables.
 
<lang snobol4> expression = "' page ' (i + 1)"
i = 7
output = eval(expression)
end</lang>
 
Output:
 
<pre> page 8</pre>
 
The built in function code() compiles complete SNOBOL4 source statements, or even complete programs. The compiled program is returned (as a value of type CODE), and when executed the program is executed in the then-current environment and has access to the then-current variables. Labels in the compiled program are added to the current program. Programs of type CODE are executed by a variant of the goto clause:
 
<lang SNOBOL4> compiled = code(' output = "Hello, world."') :s<compiled>
end</lang>
 
When passing programs to code(), semicolons are used to separate lines.
 
The calling (already-compiled) program can call, for example, functions that are defined in the code compiled at runtime, and can include gotos to labels only defined in the code compiled at runtime. Likewise, the code compiled at runtime has access to not just variables, but also files, functions, etc., that are in the already-compiled program.
 
=={{header|Tcl}}==
Anonymous user