Well, I had a good look at CUSP today, and I must admit: it is suspiciously easy to get started and enormous fun to use (for me as an amateur lisp lover). Installation was a breeze (it installs all sbcl on its own. easy!). Up and running in no time.
Respect!
Thursday, October 25, 2007
Saturday, October 20, 2007
python closure problem
I'm shocked! That doesn't make sense to me. Cfr:
>>> def acc_gen(initial_value):
... total = initial_value
... def acc(to_add):
... total += to_add
... return total
... return acc
...
>>> a = acc_gen(5)
>>> a(3)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in acc
UnboundLocalError: local variable 'total' referenced before assignment
[1]> (defun acc-gen (total) (lambda (to_add) (incf total to_add)))
ACC-GEN
[2]> (setf a (acc-gen 5))
#
[3]> (funcall a 3)
8
[4]> (funcall a 3)
11
I'm a little bit clueless, but I'm pretty sure that this is what they mean with "python doesn't support proper lexical closures"
Labels:
accumulator generator,
closure,
lisp,
python
Subscribe to:
Comments (Atom)
