Skip to content

Instantly share code, notes, and snippets.

@chikoski
Created August 23, 2018 09:52
Show Gist options
  • Save chikoski/fc1f8360b49cf7b4e304263aa61ef49d to your computer and use it in GitHub Desktop.
Save chikoski/fc1f8360b49cf7b4e304263aa61ef49d to your computer and use it in GitHub Desktop.
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