Jump to content

Runtime evaluation/In an environment: Difference between revisions

(→‎{{header|RPL}}: Alternative)
Line 992:
 
=={{header|RPL}}==
A first way to answer the task is to use the possibility of passing local variables from one program to another, the calling program being in charge of achieving the binding of values to the x variable.
≪ 2 x ^ ≫ 'POWR2' STO
3 5 ≪ → x ≪ POWR2 SWAP ≫ → x ≪ POWR2 SWAP - ≫ EVAL≫ 'DIFFP' STO
{{in}}
<pre>
5 3 DIFFP
3 5 ≪ → x ≪ POWR2 SWAP ≫ → x ≪ POWR2 - ≫ EVAL
</pre>
{{out}}
<pre>
1: 24
</pre>
Another solution is to let the algebraic interpreter do the binding:
≪ → x ≪ 2 x ^ ≫ ≫ 'POWR2' STO
{{in}}
<pre>
'POWR2(5)-POWR2(3)' EVAL
</pre>
{{out}}
1,151

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.