Runtime evaluation: Difference between revisions

add factor example
No edit summary
(add factor example)
Line 367:
57
</lang>
 
=={{header|Factor}}==
 
Arbitrary strings can be <tt>eval</tt>'d, but you must provide their stack effect.
 
<pre>
IN: scratchpad "\"Hello, World!\" print" ( -- ) eval
Hello, World!
IN: scratchpad 4 5 "+" ( a b -- c ) eval
9
</pre>
 
You can use the <tt>infer</tt> word to infer a quotation's stack effect. You can combine <tt>infer</tt> with <tt>parse-string</tt> to <tt>eval</tt> an arbitrary string without writing the stack effect yourself.
 
<pre>
( scratchpad ) "USE: math 8 9 +" dup parse-string
"USE: math 8 9 +"
[ 8 9 + ]
( scratchpad ) infer
"USE: math 8 9 +"
( x x -- x )
( scratchpad ) eval
17
</pre>
 
=={{header|Forth}}==
Anonymous user