* why does `variable-at-point' return 0?
@ 2012-04-07 0:23 Drew Adams
2012-04-16 18:07 ` Drew Adams
0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2012-04-07 0:23 UTC (permalink / raw)
To: emacs-devel
Just curious. Why doesn't `variable-at-point' return nil if there is no
variable at point?
All I can think of is that for some reason someone wanted to test using
`symbolp' instead of testing using `not' (or `and'). But I cannot imagine why.
Checking how `variable-at-point' is actually used in the source code did not
enlighten me. Each use just checks whether the value is `symbolp' and goes on
from there. An actual value of zero is never used AFAICT, except to serve as a
non-symbol.
There is no special need to distinguish nil from any variable - in Emacs Lisp
you cannot give the symbol nil a symbol-value other than nil.
It is true that (boundp nil) is true, so `boundp' is not a test of variableness.
But I don't see why it wouldn't be just as easy to test whether the value is nil
instead of testing whether it is a symbol. What am I missing?
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: why does `variable-at-point' return 0?
2012-04-07 0:23 why does `variable-at-point' return 0? Drew Adams
@ 2012-04-16 18:07 ` Drew Adams
2012-04-19 19:50 ` Štěpán Němec
2012-04-19 21:52 ` Stefan Monnier
0 siblings, 2 replies; 9+ messages in thread
From: Drew Adams @ 2012-04-16 18:07 UTC (permalink / raw)
To: emacs-devel
ping
> Just curious. Why doesn't `variable-at-point' return nil if
> there is no variable at point?
>
> All I can think of is that for some reason someone wanted to
> test using `symbolp' instead of testing using `not' (or `and').
> But I cannot imagine why.
>
> Checking how `variable-at-point' is actually used in the
> source code did not enlighten me. Each use just checks whether
> the value is `symbolp' and goes on from there. An actual value
> of zero is never used AFAICT, except to serve as a non-symbol.
>
> There is no special need to distinguish nil from any variable - in
> Emacs Lisp you cannot give the symbol nil a symbol-value other than nil.
>
> It is true that (boundp nil) is true, so `boundp' is not a
> test of variableness. But I don't see why it wouldn't be just as
> easy to test whether the value is nil instead of testing whether it
> is a symbol. What am I missing?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: why does `variable-at-point' return 0?
2012-04-16 18:07 ` Drew Adams
@ 2012-04-19 19:50 ` Štěpán Němec
2012-04-19 21:28 ` Drew Adams
2012-04-19 21:52 ` Stefan Monnier
1 sibling, 1 reply; 9+ messages in thread
From: Štěpán Němec @ 2012-04-19 19:50 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs-devel
On Mon, 16 Apr 2012 20:07:47 +0200
Drew Adams wrote:
> ping
>
>> Just curious. Why doesn't `variable-at-point' return nil if
>> there is no variable at point?
[...]
>> What am I missing?
Dunno if you're missing anything, but you're certainly not the only one
wondering. FWIW, for my purposes I've been using the function below ever
since I discovered `variable-at-point':
(defun .variable-at-point ()
"Sanitized version of the utterly [CENSORED] `variable-at-point'.
\(The latter returns 0 as the failure value. Very useful,
indeed.)"
(let ((v (variable-at-point)))
(unless (eq v 0) v)))
--
Štěpán
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: why does `variable-at-point' return 0?
2012-04-19 19:50 ` Štěpán Němec
@ 2012-04-19 21:28 ` Drew Adams
0 siblings, 0 replies; 9+ messages in thread
From: Drew Adams @ 2012-04-19 21:28 UTC (permalink / raw)
To: 'Štepán Nemec'; +Cc: emacs-devel
> >> What am I missing?
>
> Dunno if you're missing anything, but you're certainly not
> the only one wondering. FWIW, for my purposes I've been
> using the function below ever since I discovered `variable-at-point':
> ...
> (let ((v (variable-at-point)))
> (unless (eq v 0) v)))
Thanks for confirming that I might not be missing anything.
Maybe Emacs Dev would consider putting this in line with other at-point
functions.
How about deprecating `variable-at-point' and defining a new function
`var-at-point' that DTRT?
(I'm still curious how `variable-at-point' ever got to be defined that way. I
still do wonder if there wasn't perhaps a good reason at the time. I cannot
imagine one, but I've been surprised before.)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: why does `variable-at-point' return 0?
2012-04-16 18:07 ` Drew Adams
2012-04-19 19:50 ` Štěpán Němec
@ 2012-04-19 21:52 ` Stefan Monnier
2012-04-19 22:56 ` Juanma Barranquero
2012-04-20 18:14 ` Štěpán Němec
1 sibling, 2 replies; 9+ messages in thread
From: Stefan Monnier @ 2012-04-19 21:52 UTC (permalink / raw)
To: Drew Adams; +Cc: emacs-devel
>> All I can think of is that for some reason someone wanted to
>> test using `symbolp' instead of testing using `not' (or `and').
>> But I cannot imagine why.
That's most likely the reason, so as not to get tripped up by a variable
whose name happens to be "nil" (unlikely in Lisp, admittedly).
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: why does `variable-at-point' return 0?
2012-04-19 21:52 ` Stefan Monnier
@ 2012-04-19 22:56 ` Juanma Barranquero
2012-04-20 18:14 ` Štěpán Němec
1 sibling, 0 replies; 9+ messages in thread
From: Juanma Barranquero @ 2012-04-19 22:56 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Drew Adams, emacs-devel
On Thu, Apr 19, 2012 at 23:52, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> That's most likely the reason, so as not to get tripped up by a variable
> whose name happens to be "nil" (unlikely in Lisp, admittedly).
`variable-at-point' is used five times in the lisp/* sources, and in
every case there's a check like
(and (symbolp val) val)
or
(if (eq val 0) nil val)
so it seems like v-a-p needs an upgrade.
Juanma
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: why does `variable-at-point' return 0?
2012-04-19 21:52 ` Stefan Monnier
2012-04-19 22:56 ` Juanma Barranquero
@ 2012-04-20 18:14 ` Štěpán Němec
2012-04-20 22:57 ` Juanma Barranquero
2012-04-21 2:24 ` Stefan Monnier
1 sibling, 2 replies; 9+ messages in thread
From: Štěpán Němec @ 2012-04-20 18:14 UTC (permalink / raw)
To: Stefan Monnier; +Cc: Drew Adams, emacs-devel
On Thu, 19 Apr 2012 23:52:22 +0200
Stefan Monnier wrote:
>>> All I can think of is that for some reason someone wanted to
>>> test using `symbolp' instead of testing using `not' (or `and').
>>> But I cannot imagine why.
>
> That's most likely the reason, so as not to get tripped up by a variable
> whose name happens to be "nil" (unlikely in Lisp, admittedly).
^^^^^^^^
AFAIK, in "nil-lisps" like Elisp or Common Lisp that is not unlikely,
but impossible. Could you explain what you had in mind?
--
Štěpán
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: why does `variable-at-point' return 0?
2012-04-20 18:14 ` Štěpán Němec
@ 2012-04-20 22:57 ` Juanma Barranquero
2012-04-21 2:24 ` Stefan Monnier
1 sibling, 0 replies; 9+ messages in thread
From: Juanma Barranquero @ 2012-04-20 22:57 UTC (permalink / raw)
To: Štěpán Němec; +Cc: Stefan Monnier, Drew Adams, emacs-devel
On Fri, Apr 20, 2012 at 20:14, Štěpán Němec <stepnem@gmail.com> wrote:
> AFAIK, in "nil-lisps" like Elisp or Common Lisp that is not unlikely,
> but impossible. Could you explain what you had in mind?
C:\> emacs -Q --batch --eval "(unintern 'nil)" --eval "(message \"nil
= %%S\" (let ((nil t)) nil))"
nil = t
Juanma
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: why does `variable-at-point' return 0?
2012-04-20 18:14 ` Štěpán Němec
2012-04-20 22:57 ` Juanma Barranquero
@ 2012-04-21 2:24 ` Stefan Monnier
1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2012-04-21 2:24 UTC (permalink / raw)
To: Štěpán Němec; +Cc: Drew Adams, emacs-devel
>>>> All I can think of is that for some reason someone wanted to
>>>> test using `symbolp' instead of testing using `not' (or `and').
>>>> But I cannot imagine why.
>> That's most likely the reason, so as not to get tripped up by a variable
>> whose name happens to be "nil" (unlikely in Lisp, admittedly).
> AFAIK, in "nil-lisps" like Elisp or Common Lisp that is not unlikely,
> but impossible.
In the context of the discussion, the difference between "unlikely" and
"impossible" is irrelevant.
> Could you explain what you had in mind?
I work in formal methods, and from that point of view, "impossible"
would basically mean you have a proof that it can't happen, yet in
languages like Lisp "can't happen" is pretty much ... "unlikely"?
Stefan
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2012-04-21 2:24 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-07 0:23 why does `variable-at-point' return 0? Drew Adams
2012-04-16 18:07 ` Drew Adams
2012-04-19 19:50 ` Štěpán Němec
2012-04-19 21:28 ` Drew Adams
2012-04-19 21:52 ` Stefan Monnier
2012-04-19 22:56 ` Juanma Barranquero
2012-04-20 18:14 ` Štěpán Němec
2012-04-20 22:57 ` Juanma Barranquero
2012-04-21 2:24 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.