From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.devel Subject: Re: lexical-binding questions Date: Sat, 05 May 2012 08:45:43 +0200 Message-ID: <87wr4rqg6g.fsf@gmail.com> References: <871umzrvfw.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1336200364 13175 80.91.229.3 (5 May 2012 06:46:04 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 5 May 2012 06:46:04 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat May 05 08:46:03 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SQYkk-0002mM-Aa for ged-emacs-devel@m.gmane.org; Sat, 05 May 2012 08:46:02 +0200 Original-Received: from localhost ([::1]:58887 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQYkj-00024P-O8 for ged-emacs-devel@m.gmane.org; Sat, 05 May 2012 02:46:01 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQYkh-00024K-LK for emacs-devel@gnu.org; Sat, 05 May 2012 02:46:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SQYkf-0007uC-6b for emacs-devel@gnu.org; Sat, 05 May 2012 02:45:59 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:58926) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SQYke-0007ts-Vy for emacs-devel@gnu.org; Sat, 05 May 2012 02:45:57 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SQYkb-0002gK-Cq for emacs-devel@gnu.org; Sat, 05 May 2012 08:45:53 +0200 Original-Received: from lbe83-2-78-243-104-167.fbx.proxad.net ([78.243.104.167]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 05 May 2012 08:45:53 +0200 Original-Received: from thierry.volpiatto by lbe83-2-78-243-104-167.fbx.proxad.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 05 May 2012 08:45:53 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 74 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: lbe83-2-78-243-104-167.fbx.proxad.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux) Cancel-Lock: sha1:1OiW27DNuzrPgGxsVJIPp1nAqpU= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:150271 Archived-At: Thierry Volpiatto writes: > Hi, > it seem C-M-x is not working as expected in a `lexical-binding' enabled > buffer: > > #+BEGIN_SRC emacs-lisp > ;; -*- lexical-binding: t -*- > > (defun foo () > (declare (special bar)) > (let ((bar 2) > (baz 3)) > #'(lambda () (+ bar baz)))) > > ;; I expect this: > > ;; (funcall (foo)) > ;;=>Symbol's value as variable is void: bar > > #+END_SRC > > However, (funcall (foo)) return 5 until I byte-compile and load the > file. > > So my question is how do you evaluate such code when working in a > `lexical-binding' enabled buffer? > > Thanks. Also, in CL, the declare spec is placed at the beginning of the let form: #+BEGIN_SRC lisp (defun foo () (let ((bar 2) (baz 3)) (declare (special bar)) #'(lambda () (+ bar baz)))) (foo) ;; => # (funcall (foo)) ;; =>The variable BAR is unbound. ;; [Condition of type UNBOUND-VARIABLE] #+END_SRC In elisp the declare form need to be placed BEFORE the let form (see above), otherwise it have no effect. the manual say: --8<---------------cut here---------------start------------->8--- -- Special Form: declare decl-specs... This macro is used to make declarations within functions and other code. Common Lisp allows declarations in various locations, generally at the beginning of any of the many "implicit `progn's" throughout Lisp syntax, such as function bodies, `let' bodies, etc. Currently the only declaration understood by `declare' is `special'. --8<---------------cut here---------------end--------------->8--- So where is the beginning of a let/progn form? ;; here ? (let ((bar 2)) ;; or here ? Why does it behave differently from CL? -- Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997