-
-
Save dgageot/508548 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foldingFunction=method(sum, x, | |
case(x, | |
"+", [sum pop! + sum pop!], | |
"*", [sum pop! * sum pop!], | |
"-", [sum pop! - sum pop!], | |
"/", [sum pop! / sum pop!], | |
[x toRational] | |
) + sum | |
) | |
"8 1 2 + 5 * +" split fold([], sum, x, foldingFunction(sum, x)) println |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
List foldingFunction = method(x,
append!(case(x,
or("+", "*", "-", "/"), Message fromText(x) appendArgument(pop!) sendTo(pop!),
x toRational
)
)
)
"8 1 2 + 5 * +" split prepend!([]) fold(foldingFunction) println