From 8d4cb2b74e8d8c18859198900a44241b616dacb7 Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Sun, 5 Apr 2015 12:46:31 -0700 Subject: [PATCH] Added strings to the things it understands, although it's just treated like another Javascript literal, and there's no type checking. Also, tried very hard to write down my inspiration for how closures work, because it's something I'm not "ah-hah"ing about, but rather grinding about. --- lib/eval.coffee | 1 + lib/fn.coffee | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/eval.coffee b/lib/eval.coffee index a37a64c..88597f2 100644 --- a/lib/eval.coffee +++ b/lib/eval.coffee @@ -5,6 +5,7 @@ lispeval = (element, scope) -> switch (car element) when 'number' then parseInt (cadr element), 10 + when 'string' then (cadr element) when 'symbol' then lookup scope, (cadr element) when 'list' proc = lispeval (caadr element), scope diff --git a/lib/fn.coffee b/lib/fn.coffee index 4f51a49..f54534d 100644 --- a/lib/fn.coffee +++ b/lib/fn.coffee @@ -23,9 +23,15 @@ module.exports = cmap((cdr cells), (cdr params), nscope))(cells, params, {}) # Execute and evaluate the body, creating an inner scope that - # consists of all the bound variables (the parameters) evaluated - # in the context of the function call, and all of free variables - # evaluated in the context of the defining scope. + # consists of: (1) the bound variables (the parameters) + # evaluated in the context of the function call, because that's + # where they were encountered (2) the free variables evaluated + # in the context of the defining scope, because that's where + # *they* were encountered. + # + # While this inspiration comes from Coglan, the clearest + # explanation is from Lisperator's 'make_lambda' paragraph at + # http://lisperator.net/pltut/eval1/ inner_scope = cons(new_scope, defining_scope) (nval = (body, memo) ->