emacs-devel
[Top][All Lists]
Advanced

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

Re: Evil defvars in org.el


From: Johan Bockgård
Subject: Re: Evil defvars in org.el
Date: Fri, 04 May 2012 22:53:12 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> It seems to me that this is something where there really ought to be
>> a general Emacs solution (dynamic-let or whatever).
>
> There is such a thing: (defvar <foo>).

It currently has a number of problems:

- The scoping of defvar is unclear and changes when the code is
compiled:

(setq lexical-binding t)

(defun a ()
  (let  ((f (lambda () x))
         (g (lambda () (defvar x))))
    (funcall g)
    (let ((x 0))
      (funcall f))))

(defun b ()
  (let (f g)
    (setq f (lambda () x)
          g (lambda () (defvar x)))
    (funcall g)
    (let ((x 0))
      (funcall f))))

(defun c ()
  (let  ((f (lambda () x)))
    (catch nil (defvar x))
    (let ((x 0))
      (funcall f))))

(defun d ()
  (let  ((f (lambda () x)))
    (progn (defvar x) (let (x)))  ; "dlet"
    (let ((x 0))
      (funcall f))))

;; Interpreted
(a) => error: (void-variable x)
(b) => 0
(c) => 0
(d) => 0

;; Compiled
(a) => error
(b) => error
(c) => error
(d) => 0

etc.


- Invalid byte code is generated when the same symbol is used as both a
lexical and a dynamic variable:

(setq lexical-binding t)
(setq foo (byte-compile
           '(lambda ()
              (let (x)
                (defvar x)
                (let (x) 0)))))

(disassemble foo)
byte code:
  doc:   ...
  args: 0
0       constant  nil
1       dup
2       varbind   x    <<<< No matching `unbind'
3       constant  0
4       return

(funcall foo)

   => Fatal error (6)Aborted



reply via email to

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