help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Real-life examples of lexical binding in Emacs Lisp


From: Pascal J. Bourguignon
Subject: Re: Real-life examples of lexical binding in Emacs Lisp
Date: Wed, 17 Jun 2015 12:53:01 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

"Pascal J. Bourguignon" <pjb@informatimago.com> writes:

>      ;; and then in some unrelated code in a different file:
>
>      (setq lexical-binding nil)
>      (let ((scratch-buffer (get-buffer-create "*scratch*")))
>         (with-current-buffer scratch-buffer (insert "hello"))
>         (some-function "Howdy?")
>         (with-current-buffer scratch-buffer
>           (buffer-substring (point-min) (point-max))))

Without lexical binding, to try to get some independence from other
functions, you would have to PREFIX ALL THE LOCAL VARIABLES WITH
FUNCTION SPECIFIC PREFIXES!
 

    (defun pjb-package--pjb-example-function ()
      (let ((pjb-package--pjb-example-function--scratch-buffer 
(get-buffer-create "*scratch*")))
         (with-current-buffer pjb-package--pjb-example-function--scratch-buffer
            (insert "hello"))
         (some-function "Howdy?")
         (with-current-buffer pjb-package--pjb-example-function--scratch-buffer
           (buffer-substring (point-min) (point-max)))))

And this is only a convention that wouldn't prevent
another-package--evil-function to modify
pjb-package--pjb-example-function--scratch-buffer anyways.


Now look at all the el code arround, and count how many local variables
are named like this!!!  


-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk


reply via email to

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