[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: lexical-binding questions

From: Thierry Volpiatto
Subject: Re: lexical-binding questions
Date: Sat, 05 May 2012 08:45:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

Thierry Volpiatto <address@hidden> 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
> 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

#+BEGIN_SRC lisp
(defun foo ()
  (let ((bar 2)
        (baz 3))
    (declare (special bar))
    #'(lambda () (+ bar baz))))
;; => #<FUNCTION (LAMBDA () :IN FOO) {B08BF6D}>
(funcall (foo))
;; =>The variable BAR is unbound.
;;    [Condition of type UNBOUND-VARIABLE]


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
--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?

Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]