LispInSmallPieces/chapter1/lookup.coffee

9 lines
232 B
CoffeeScript
Raw Normal View History

2015-05-14 05:28:55 +00:00
{nilp, car, cdr} = require './lists'
module.exports = lookup = (scopes, name) ->
throw new Error "Unknown variable '#{name}'" if nilp scopes
scope = car scopes
return scope[name] if scope[name]?
lookup((cdr scopes), name)