here's something i'll explain to tomorrow (using "env" to implement
local variables).
t
p.s. motivating example. local vars in lisp. if the following python
code was inserted into lis.py, then you code as follows:
(begin
(let ((a 1) # <== define some local vars
(b 2)
c
(d (+ a b)))
(begin
(say a) # prints 1
(say b) # prints 2
(say c) # prints empty list
(say d) # prints 3
)
)
(say a) #<== crashes. no such var as "a"
)
----------------------------
Begin Python code.
elif x[0] == 'let':
# (let (decls*) form) declares local variables that exist for the evluation
# of the passed form. It returns whatever "form" evaluates to.
#
# A decl has one of two forms:
# decl -> var
# decl -> (var exp)
#
# In the first case, the local variable "var" will have the value "nil". In
# the second, "var" will be set to whatever value "exp" evaluates.
#
# Note that "let" is written so that whatever local variables you declare
# will be visible to the subsequent local variables. That way, you can use
# them immediately if you'd like.
nestedEnv = Env(outer=env)
for local in x[1]:
if isa(local, list):
localVar = local[0]
nestedEnv[localVar] = eval(local[1], nestedEnv)
else:
nestedEnv[local] = list()
return eval(x[2], nestedEnv)
--
:: there are some who call me...
tim.m...@gmail.com
:: prof @ cs.ai.se.csee.wvu.usa.sol.virgo.all.nil
::
+1-304-376-2859
::
http://menzies.us (skype = menzies.tim)
<hubris>
vita= http://
goo.gl/8eNhY
pubs= http://
goo.gl/8KPKA
stats= http://
goo.gl/vggy1
wow = http://
goo.gl/2Wg9A
</hubris>