Parsing/RPN calculator algorithm: Difference between revisions

Added 11l
(Added Wren)
(Added 11l)
Line 22:
*   [[Arithmetic evaluation]].
<br><br>
 
=={{header|11l}}==
{{trans|Python}}
 
<lang 11l>[Float] a
[String = (Float, Float -> Float)] b
b[‘+’] = (x, y) -> y + x
b[‘-’] = (x, y) -> y - x
b[‘*’] = (x, y) -> y * x
b[‘/’] = (x, y) -> y / x
b[‘^’] = (x, y) -> y ^ x
 
L(c) ‘3 4 2 * 1 5 - 2 3 ^ ^ / +’.split(‘ ’)
I c C b
V first = a.pop()
V second = a.pop()
a.append(b[c](first, second))
E
a.append(Float(c))
print(c‘ ’a)</lang>
 
{{out}}
<pre>
3 [3]
4 [3, 4]
2 [3, 4, 2]
* [3, 8]
1 [3, 8, 1]
5 [3, 8, 1, 5]
- [3, 8, -4]
2 [3, 8, -4, 2]
3 [3, 8, -4, 2, 3]
^ [3, 8, -4, 8]
^ [3, 8, 65536]
/ [3, 0.00012207]
+ [3.00012207]
</pre>
 
=={{header|360 Assembly}}==
1,481

edits