From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tiago Charters de Azevedo Newsgroups: gmane.emacs.help 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 Message-ID: <87my8izafy.fsf@cii.fc.ul.pt> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1244499762 17352 80.91.229.12 (8 Jun 2009 22:22:42 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 8 Jun 2009 22:22:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Jun 09 00:22:40 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MDnEh-00084S-F2 for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Jun 2009 00:22:35 +0200 Original-Received: from localhost ([127.0.0.1]:53202 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MDnEg-0003Dd-PH for geh-help-gnu-emacs@m.gmane.org; Mon, 08 Jun 2009 18:22:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MDmK2-00027T-1Z for help-gnu-emacs@gnu.org; Mon, 08 Jun 2009 17:24:02 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MDmJw-00027D-2l for help-gnu-emacs@gnu.org; Mon, 08 Jun 2009 17:24:00 -0400 Original-Received: from [199.232.76.173] (port=37563 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MDmJv-00027A-Tu for help-gnu-emacs@gnu.org; Mon, 08 Jun 2009 17:23:55 -0400 Original-Received: from alfmail.cii.fc.ul.pt ([194.117.6.6]:53898) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MDmJv-0005cZ-7Y for help-gnu-emacs@gnu.org; Mon, 08 Jun 2009 17:23:55 -0400 Original-Received: from localhost (alfmail.cii.fc.ul.pt [10.117.6.6]) by alfmail.cii.fc.ul.pt (8.13.5/8.13.5) with ESMTP id n58LNaur019007 for ; Mon, 8 Jun 2009 22:23:42 +0100 User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) X-Virus-Scanned: by amavisd-new X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-3.0 (alfmail.cii.fc.ul.pt [10.117.6.6]); Mon, 08 Jun 2009 22:23:44 +0100 (WEST) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Mailman-Approved-At: Mon, 08 Jun 2009 18:18:48 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:65064 Archived-At: 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