|
From: | Tiago Charters de Azevedo |
Subject: | The Paul Graham's "Revenge of the nerds" cummulator function and the solution in Emacs Lisp |
Date: | Mon, 08 Jun 2009 21:23:45 +0000 |
User-agent: | Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
I've been reading Paul Graham's "Revenge of the nerds" (http://www.paulgraham.com/icad.html) particularly the appendix. It states the problem of writing "a function that generates accumulators-- a function that takes a number n, and returns a function that takes another number i and returns n incremented by i. (That's incremented by, not plus. An accumulator has to accumulate.)" Should not the function foo in Common Lisp work with Emacs Lisp? (defun foo (n) (lambda (i) (incf n i))) by setting (setq a (foo 3)) followed by (funcall a 1) When I try to evaluate (funcall a 1) in Emacs (in emacs-lisp mode) I get: Debugger entered--Lisp error: (void-variable n) (+ n i) (setq n (+ n i)) (incf n i) (lambda (i) (incf n i))(1) funcall((lambda (i) (incf n i)) 1) eval((funcall a 1)) eval-last-sexp-1(nil) eval-last-sexp(nil) call-interactively(eval-last-sexp It seems that emacs considers that n is a local variable because it is inside a lambda expression? Is this a bug? Or I'm missing something? Thanks tca -- URL: http://www.diale.org Email: tca@cii.fc.ul.pt Phone: +351 21 7904874 (internal: 4274) Fax: +351 21 795 4288
[Prev in Thread] | Current Thread | [Next in Thread] |