all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Confusion about elisp symbols and defuns
@ 2014-09-24  7:23 H. Dieter Wilhelm
  2014-09-24  9:18 ` Nicolas Richard
  0 siblings, 1 reply; 3+ messages in thread
From: H. Dieter Wilhelm @ 2014-09-24  7:23 UTC (permalink / raw)
  To: help-gnu-emacs

Hello (),

Calc checks in calc-var-value if variables are bound.  This works for
examplwe with the variable symbol `g'

(calc-var-value 'g)
nil

but bombs for the variable `v'

(calc-var-value 'v)
=> error

The reason seems to me that somehow over the parameter name (v) of the
defun the symbol `v' becomes bound.  (Excuse my layman interpretation.)

(makunbound 'g)
g

(makunbound 'v)
v

(symbolp 'v)
t

(boundp 'v)
nil

(boundp 'g)
nil

(defun bla (v)
  (boundp v))
bla

(bla 'g)
nil

(bla 'v)
t

(defun foo (v)
  (makunbound v)
  (boundp v))
foo

(foo 'g)
nil

(foo 'v)
=> error signal


How would you change the calc-var-value to avoid this trap?

Thanks for any enlightenment

       Dieter
-- 
Best wishes
H. Dieter Wilhelm
Darmstadt, Germany




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Confusion about elisp symbols and defuns
  2014-09-24  7:23 H. Dieter Wilhelm
@ 2014-09-24  9:18 ` Nicolas Richard
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Richard @ 2014-09-24  9:18 UTC (permalink / raw)
  To: H. Dieter Wilhelm; +Cc: help-gnu-emacs

dieter@duenenhof-wilhelm.de (H. Dieter Wilhelm) writes:

> Hello (),
>
> Calc checks in calc-var-value if variables are bound.  This works for
> examplwe with the variable symbol `g'
>
> (calc-var-value 'g)
> nil
>
> but bombs for the variable `v'
>
> (calc-var-value 'v)> => error

The error is (void-function v) and that comes from the fact calc-var-value does:
(set v (funcall (symbol-value v)))
It does so after checking (symbolp (symbol-value v)) but does not check
that this symbol indeed has a function definition.

I don't know why calc-var-value does what it does, so I don't know what
the fix is. Perhaps checking for (fboundp (symbol-value v)) would
help a bit (or functionp instead of fboundp).

OTOH, obviously calc-var-value believes that it has the right to change
the value cell of its argument, so I guess calling (calc-var-value 'v)
doesn't actually make sense, and there's no point in fixing
calc-var-value for this specific wrong use of it.

-- 
Nicolas Richard



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Confusion about elisp symbols and defuns
       [not found] <mailman.9462.1411543422.1147.help-gnu-emacs@gnu.org>
@ 2014-09-24 12:51 ` Stefan Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2014-09-24 12:51 UTC (permalink / raw)
  To: help-gnu-emacs

> (defun foo (v)
>   (makunbound v)
>   (boundp v))
> foo

> (foo 'g)
> nil

> (foo 'v)
> => error signal

> How would you change the calc-var-value to avoid this trap?

Use lexical-binding.


        Stefan


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-24 12:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.9462.1411543422.1147.help-gnu-emacs@gnu.org>
2014-09-24 12:51 ` Confusion about elisp symbols and defuns Stefan Monnier
2014-09-24  7:23 H. Dieter Wilhelm
2014-09-24  9:18 ` Nicolas Richard

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.