Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Last active August 29, 2015 14:24
Show Gist options
  • Save lambda-fairy/55d10e68f60730964cd9 to your computer and use it in GitHub Desktop.
Save lambda-fairy/55d10e68f60730964cd9 to your computer and use it in GitHub Desktop.
M-expression desugaring
f x y z => f[x, y, z]
f : g : x => f[g[x]]
{x, y, z} => Do[x, y, z]
----------------
If (x == 0) {
Say['Hello!']
} {
Say['Ducks']
}
=>
If[==[x, 0], Do[Say['Hello!'], Do[Say['Ducks']]]
----------------
Rec {
odd = Fn[x]: If (x == 0) False even[x - 1]
even = Fn[x]: If (x == 0) True odd[x - 1]
}
=>
Rec[Do[
=[odd, Fn[x][If[==[x, 0], False, even[-[x, 1]]]]],
=[even, Fn[x][If[==[x, 0], True, odd[-[x, 1]]]]]
]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment