Skip to content

Instantly share code, notes, and snippets.

@dgageot
Created August 4, 2010 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dgageot/508548 to your computer and use it in GitHub Desktop.
Save dgageot/508548 to your computer and use it in GitHub Desktop.
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
@dgageot
Copy link
Author

dgageot commented Aug 5, 2010

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment