Last active
August 29, 2015 14:18
-
-
Save zeusdeux/93b814c3489c43c236a4 to your computer and use it in GitHub Desktop.
RC LANG
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
// sugared fib is below | |
fib n | |
let one = 1 | |
if n == 0 | |
then | |
one | |
else | |
if n == 1 | |
then | |
one | |
else | |
fib(n-1) + fib(n-2) | |
// desugared fib is below | |
// { } -> contain blocks and blocks are thunks so they can be functions too. | |
// Blocks are special functions called thunk that evaluate to a value and then remember it. | |
// On further invocation, blocks just return the value instead of executing their fn body | |
// arguments is what the runtime gives to fib when fib is called | |
fib arguments { | |
let n = arguments[0] | |
let one = 1 | |
let cond1 = n == 0 | |
// if is a function that has the following arguments: | |
// if condition thenBlock elseBlock | |
if cond1 { one } { //elseBlock | |
let cond2 = n == 1 | |
if cond2 { one } { //elseBlock | |
let arg1 = n - 1 | |
let arg2 = n - 2 | |
let result1 = fib arg1 | |
let result2 = fib arg2 | |
result1 + result2 | |
} | |
} | |
// functions can only take value not an expression which is why fib(n-1) + fib(n-2) is desugared as lines 15-19 | |
// + is a function that takes two values, so we desugar to get those values before calling + | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment