Runtime evaluation: Difference between revisions
Content added Content deleted
No edit summary |
(add factor example) |
||
Line 367: | Line 367: | ||
57 |
57 |
||
</lang> |
</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}}== |
=={{header|Forth}}== |