From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: The Paul Graham's "Revenge of the nerds" cummulator function and the solution in Emacs Lisp Date: Tue, 09 Jun 2009 08:40:59 +0200 Message-ID: <871vptzz7o.fsf@thinkpad.tsdh.de> References: <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 1244529710 13532 80.91.229.12 (9 Jun 2009 06:41:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 9 Jun 2009 06:41:50 +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 08:41:47 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 1MDv1l-0000nC-SQ for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Jun 2009 08:41:46 +0200 Original-Received: from localhost ([127.0.0.1]:48781 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MDv1l-00006O-Dm for geh-help-gnu-emacs@m.gmane.org; Tue, 09 Jun 2009 02:41:45 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MDv1O-0008Vk-Gf for help-gnu-emacs@gnu.org; Tue, 09 Jun 2009 02:41:22 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MDv1J-0008Tl-Th for help-gnu-emacs@gnu.org; Tue, 09 Jun 2009 02:41:21 -0400 Original-Received: from [199.232.76.173] (port=38628 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MDv1J-0008Ti-OK for help-gnu-emacs@gnu.org; Tue, 09 Jun 2009 02:41:17 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:7804) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MDv1J-0001nC-7Q for help-gnu-emacs@gnu.org; Tue, 09 Jun 2009 02:41:17 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MDv1F-0001S2-Gt for help-gnu-emacs@gnu.org; Tue, 09 Jun 2009 02:41:13 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MDv1B-0004Ye-Hm for help-gnu-emacs@gnu.org; Tue, 09 Jun 2009 06:41:09 +0000 Original-Received: from 141.26.67.5 ([141.26.67.5]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Jun 2009 06:41:09 +0000 Original-Received: from tassilo by 141.26.67.5 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 09 Jun 2009 06:41:09 +0000 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 38 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 141.26.67.5 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.94 (gnu/linux) Cancel-Lock: sha1:1LlxwpOHVmtxOTu8fZH2mvBx9Uc= X-Detected-Operating-System: by mx20.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) 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:65074 Archived-At: Tiago Charters de Azevedo writes: Hi Tiago, > Should not the function foo in Common Lisp work with Emacs Lisp? > > (defun foo (n) > (lambda (i) > (incf n i))) No, that won't work because emacs has no lexical scoping and that code is a closure. See the elisp manual: ,----[ (info "(elisp)Extent") ] | To illustrate this, the function below, `make-add', returns a | function that purports to add N to its own argument M. This would work | in Common Lisp, but it does not do the job in Emacs Lisp, because after | the call to `make-add' exits, the variable `n' is no longer bound to | the actual argument 2. | | (defun make-add (n) | (function (lambda (m) (+ n m)))) ; Return a function. | => make-add | (fset 'add2 (make-add 2)) ; Define function `add2' | ; with `(make-add 2)'. | => (lambda (m) (+ n m)) | (add2 4) ; Try to add 2 to 4. | error--> Symbol's value as variable is void: n | | Some Lisp dialects have "closures," objects that are like functions | but record additional variable bindings. Emacs Lisp does not have | closures. `---- Bye, Tassilo -- Chuck Norris once rode a bull, and nine months later it had a calf.