Created
August 23, 2018 09:52
-
-
Save chikoski/fc1f8360b49cf7b4e304263aa61ef49d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const example = ["+", 1, 2, 3]; | |
const builtin = { | |
"+": (a, b) => a + b, | |
}; | |
const resolve = symbol => builtin[symbol]; | |
const isUndefined = value => value == null; | |
const car = list => list[0]; | |
const cdr = list => list.slice(1); | |
const apply = (func, args) => { | |
return args.reduce(func); | |
}; | |
const evl = list => { | |
const args = cdr(list); | |
const f = resolve(car(list)); | |
return isUndefined(f) ? args.unshift(f) : apply(f, args); | |
}; | |
export default { | |
eval: evl, | |
apply, | |
example | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment