 {inspect} = require "util"
 print = require "./print"
 
+ntype = (node) -> car node
+nvalu = (node) -> cadr node
+
 class Value
-
-class Environment
 
 class Continuation
   constructor: (@k) ->
+  invoke: (v, env, kont) ->
+    if nilp cdr v
+      resume @k, (car v)
+    else
+      throw "Continuations expect one argument", [v, env, kont]
+
+# Abstract class representing the environment
+
+class Environment
+  lookup: -> throw "Nonspecific invocation"
+  update: -> throw "Nonspecific invocation"
+
+# Base of the environment stack.  If you hit this, your variable was
+# never found for lookup/update.  Note that at this time in the
+# class, you have not 
 
 class NullEnv extends Environment
   lookup: -> throw "Unknown variable"
   update: -> throw "Unknown variable"
-  
+
+# This appears to be an easy and vaguely abstract handle to the
+# environment.  The book is not clear on the distinction between the
+# FullEnv and the VariableEnv.
+            
 class FullEnv extends Environment
   constructor: (@others, @name) ->
   lookup: (name, kont) ->
     @others.lookup name, kont
   update: (name, kont, value) ->
     @others.update name, kont, value
+
+# This is the classic environment pair; either it's *this*
+# environment, or it's a parent environment, until you hit the
+# NullEnv.
 
 class VariableEnv extends FullEnv
   constructor: (@others, @name, @value) ->

definitial "#t", true
definitial "#f", the_false_value
definitial "nil", nil
definitial "foo"
definitial "bar"
definitial "fib"
definitial "fact"

defpredicate = (name, nativ, arity) ->
  defprimitive name, ((a, b) -> if nativ.call(null, a, b) then true else the_false_value), arity


# LAMBDA

evaluateLambda = (names, exp, env, kont) ->
  resume kont, new Function names, exp, env

class Function extends Value
