emacs-devel
[Top][All Lists]
Advanced

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

Re: lexical-binding defined by the caller not the called?


From: Pascal J. Bourguignon
Subject: Re: lexical-binding defined by the caller not the called?
Date: Sun, 28 Apr 2013 13:53:43 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Nic Ferrier <address@hidden> writes:

> Imagine this is a file:
>
> ;;; -*- lexical-binding: t -*-
>
> (defun my-cool-fun ()
>   lexical-binding)
>
> (ert-deftest my-cool-fun ()
>   (should (my-cool-fun)))
>
> (ert 'my-cool-fun)
>
> ;;; End
>
>
> eval-buffer that and it fails. Why does it fail? it appears that
> lexical-binding is defined by the caller of a function, not the called
> function (and the file defining ert is not lexical-binding: t). 
>
> I thought it was the other way around.
>
> Am I seeing some bug or is this the correct behaviour?

It fails because lexical-binding is a special variable (in CL terms).


---(cool.el)------------------------------------------------------------
;;; -*- lexical-binding: t -*-

(let ((lexical-variable 42))
 (defun my-cool-fun ()
   lexical-variable)) ; this lexical-variable is a lexical variable

;;; End
------------------------------------------------------------------------


---(cool-test.el)-------------------------------------------------------
;;; -*- lexical-binding: nil -*-

(ert-deftest my-cool-fun ()
   (should (let ((lexical-variable 'not!)) ; this lexical-variable is not
              (eql 42 (my-cool-fun)))))    ; a lexical variable!

(ert 'my-cool-fun)

;;; End
------------------------------------------------------------------------


Selector: my-cool-fun
Passed: 1
Failed: 0
Total:  1/1

Started at:   2013-04-28 13:51:49+0200
Finished.
Finished at:  2013-04-28 13:51:49+0200




-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.




reply via email to

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