Runtime evaluation/In an environment: Difference between revisions

Content added Content deleted
m (→‎{{header|Factor}}: remove some whitespace)
m (→‎{{header|Factor}}: tone down some snark)
Line 251: Line 251:


=={{header|Factor}}==
=={{header|Factor}}==
Being a stack-based language, there is no need to bind data stack objects to a variable name. This is the idiomatic way to do it, with <code>eval</code> referencing what it needs from the data stack:
Being a stack-based language, there is usually no need to bind data stack objects to a variable name. This is the idiomatic way to do it, with <code>eval</code> referencing what it needs from the data stack:
<lang factor>USE: eval
<lang factor>USE: eval
: eval-bi@- ( a b program -- n )
: eval-bi@- ( a b program -- n )
Line 261: Line 261:
<lang factor>IN: scratchpad 9 4 [ dup * ] bi@- .
<lang factor>IN: scratchpad 9 4 [ dup * ] bi@- .
65</lang>
65</lang>
However, to be pedantic about it, we can adhere to the letter of the task. Note that although we are using a dynamic variable for x, it exists in a temporary, non-global namespace. As far as I can tell, <code>eval</code> is unaware of surrounding lexical scope.
However, we can adhere to the letter of the task. Although we are using a dynamic variable for x, it exists in a temporary, non-global namespace. As far as I can tell, <code>eval</code> is unaware of surrounding lexical scope.
<lang factor>SYMBOL: x
<lang factor>SYMBOL: x
: eval-with-x ( a b program -- n )
: eval-with-x ( a b program -- n )