[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Extending TeX-read-key-val
From: |
Tassilo Horn |
Subject: |
Re: Extending TeX-read-key-val |
Date: |
Sun, 24 Oct 2021 16:09:30 +0200 |
User-agent: |
mu4e 1.7.3; emacs 29.0.50 |
Arash Esbati <arash@gnu.org> writes:
Hi Arash & Keita,
>> Two minor points I noticed:
>> 1. Maybe
>> (symbol-value key-val-alist)
>> is more appropriate than
>> (eval key-val-alist t)
>> for its directness.
>
> In general, you're right, but since we have turned on lexical binding in
> AUCTeX, we have this situation:
>
> ,----[ C-h f eval RET ]
> | eval is a built-in function in ‘C source code’.
> |
> | (eval FORM &optional LEXICAL)
> |
> | Evaluate FORM and return its value.
> | If LEXICAL is t, evaluate using lexical scoping.
> | LEXICAL can also be an actual lexical environment, in the form of an
> | alist mapping symbols to their value.
> `----
>
> and
>
> ,----[ C-h f symbol-value RET ]
> | symbol-value is a built-in function in ‘C source code’.
> |
> | (symbol-value SYMBOL)
> |
> | Return SYMBOL’s value. Error if that is void.
> | Note that if ‘lexical-binding’ is in effect, this returns the
> | global value outside of any lexical scope.
> `----
Hm, I don't really understand that sentence.
--8<---------------cut here---------------start------------->8---
;; -*- lexical-binding: t; -*-
(defvar foo 1)
(defun gimme-val-fn ()
`(,(list foo (symbol-value 'foo) (eval 'foo t))
,@(let ((foo 2))
(list
(list foo (symbol-value 'foo) (eval 'foo t))
(let ((f (lambda ()
(list foo (symbol-value 'foo) (eval 'foo t)))))
(cons (funcall f)
f))))))
(defun gimme-val-fn2 ()
(let ((vals (gimme-val-fn)))
(append vals
(list (funcall (cdr (nth 2 vals)))
(eval `(funcall ,(cdr (nth 2 vals))) t)))))
(gimme-val-fn2)
;;=> ((1 1 1) (2 2 2)
;; ((2 2 2) . #[0 "\300J\301\300\302\"E\207" [foo eval t] 5])
;; (1 1 1) (1 1 1))
--8<---------------cut here---------------end--------------->8---
In all cases, just foo, symbol-value, and eval return the same value
here (emacs master) for the special variable foo, i.e., always foo's
dynamic value at the place where it is called.
And both symbol-value and eval error with void-variable if the given
symbol is not a defvar-ed/global variable.
So I don't see how a symbol could have both a global value, and a
lexical value where symbol-value would return the former. I mean, if it
is a global/special variable, `let' gives it a dynamic value, not a
lexical value.
(info "(elisp) Accessing Variables") doesn't enlighten me, too.
Bye,
Tassilo
- Extending TeX-read-key-val, Arash Esbati, 2021/10/22
- Re: Extending TeX-read-key-val, Ikumi Keita, 2021/10/23
- Re: Extending TeX-read-key-val, Arash Esbati, 2021/10/24
- Re: Extending TeX-read-key-val,
Tassilo Horn <=
- Re: Extending TeX-read-key-val, Arash Esbati, 2021/10/27
- Re: Extending TeX-read-key-val, Tassilo Horn, 2021/10/28
- lexical and dynamic binding, Ikumi Keita, 2021/10/28
- Re: lexical and dynamic binding, Tassilo Horn, 2021/10/28
- Re: lexical and dynamic binding, Ikumi Keita, 2021/10/28
- Re: lexical and dynamic binding, Arash Esbati, 2021/10/28
- Re: Extending TeX-read-key-val, Ikumi Keita, 2021/10/25