Skip to content

Instantly share code, notes, and snippets.

@zeusdeux
Last active August 29, 2015 14: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 zeusdeux/93b814c3489c43c236a4 to your computer and use it in GitHub Desktop.
Save zeusdeux/93b814c3489c43c236a4 to your computer and use it in GitHub Desktop.
RC LANG
// 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