Discussion:
setf not working
Didier Verna
2013-10-03 06:48:50 UTC
Permalink
Hello,

yesterday, I fell on something extremely weird, or at least, which I
currently fail to understand. Basically, after a (defvar *var*), there
are times when (setq *var* '(0 0)) doesn't work (the previous value of
*var* remains in effect).

I cannot currently provide a minimal example because the situation
involves several levels of nested macro / function calls in code I
didn't write (*var* is solely mine though).

At first, I thought I had fallen on a compiler bug, but I get the same
behavior with at least 3 lisp implementations.

I ultimately found a workaround, consisting in using (list 0 0) instead
of '(0 0) in the assignment. I'm hoping this would be a clue to someone
here to get at least a direction for investigating...

Thanks.
--
Resistance is futile. You will be jazzimilated.

Lisp, Jazz, Aïkido: http://www.didierverna.info
Pascal Costanza
2013-10-03 07:11:05 UTC
Permalink
Is it possible to see the not minimal example?

Pascal

Sent from my iPad
Post by Didier Verna
Hello,
yesterday, I fell on something extremely weird, or at least, which I
currently fail to understand. Basically, after a (defvar *var*), there
are times when (setq *var* '(0 0)) doesn't work (the previous value of
*var* remains in effect).
I cannot currently provide a minimal example because the situation
involves several levels of nested macro / function calls in code I
didn't write (*var* is solely mine though).
At first, I thought I had fallen on a compiler bug, but I get the same
behavior with at least 3 lisp implementations.
I ultimately found a workaround, consisting in using (list 0 0) instead
of '(0 0) in the assignment. I'm hoping this would be a clue to someone
here to get at least a direction for investigating...
Thanks.
--
Resistance is futile. You will be jazzimilated.
Lisp, Jazz, Aïkido: http://www.didierverna.info
Alessio Stalla
2013-10-03 07:17:15 UTC
Permalink
This sounds really weird. Are you providing the full (setq) form to those
macros, or the var and value separately? The fact that '(0 0) does not work
but (list 0 0) does smells like there's some compiler macro triggering on
(constantp value).
Post by Didier Verna
Hello,
yesterday, I fell on something extremely weird, or at least, which I
currently fail to understand. Basically, after a (defvar *var*), there
are times when (setq *var* '(0 0)) doesn't work (the previous value of
*var* remains in effect).
I cannot currently provide a minimal example because the situation
involves several levels of nested macro / function calls in code I
didn't write (*var* is solely mine though).
At first, I thought I had fallen on a compiler bug, but I get the same
behavior with at least 3 lisp implementations.
I ultimately found a workaround, consisting in using (list 0 0) instead
of '(0 0) in the assignment. I'm hoping this would be a clue to someone
here to get at least a direction for investigating...
Thanks.
--
Resistance is futile. You will be jazzimilated.
Lisp, Jazz, Aïkido: http://www.didierverna.info
--
Some gratuitous spam:

http://ripple.com <http://ripple-project.org> Ripple, social credit system
http://common-lisp.net/project/armedbear ABCL, Common Lisp on the JVM
http://code.google.com/p/tapulli my Lisp open source projects
http://www.manydesigns.com/ ManyDesigns Portofino, open source model-driven
Java web application framework
Willem Broekema
2013-10-03 07:40:43 UTC
Permalink
Post by Didier Verna
Basically, after a (defvar *var*), there
are times when (setq *var* '(0 0)) doesn't work (the previous value of
*var* remains in effect).
I guess you are modifying the value of *var*, which is not allowed if it is
a quoted list. That's why you need e.g. (list .. ..) or (copy-tree '(..
..)) instead of '(.. ..).
http://stackoverflow.com/questions/10365470/modifying-a-list-passed-as-a-parameter-gives-different-results-in-sbcl-and-clisp

- Willem
Elias Mårtenson
2013-10-03 07:44:09 UTC
Permalink
Post by Willem Broekema
I guess you are modifying the value of *var*, which is not allowed if it is
a quoted list. That's why you need e.g. (list .. ..) or (copy-tree '(.. ..))
instead of '(.. ..).
http://stackoverflow.com/questions/10365470/modifying-a-list-passed-as-a-parameter-gives-different-results-in-sbcl-and-clisp
(SETQ *var* ...) does not change the list. It merely reassigns the variable.
Willem Broekema
2013-10-03 07:50:56 UTC
Permalink
Post by Willem Broekema
Post by Willem Broekema
I guess you are modifying the value of *var*, which is not allowed if it
is
Post by Willem Broekema
a quoted list. That's why you need e.g. (list .. ..) or (copy-tree '(..
..))
Post by Willem Broekema
instead of '(.. ..).
http://stackoverflow.com/questions/10365470/modifying-a-list-passed-as-a-parameter-gives-different-results-in-sbcl-and-clisp
(SETQ *var* ...) does not change the list. It merely reassigns the variable.
The value that is assigned, that is the problem. That is probably a
modified literal list.

If there is literally this in the code: (setq *var* '(. . .))
then the compiler is free to extract that '(. . .) part and reuse it all
the time this setq form is executed. It can create one literal object and
keep it in memory, and always uses it as value. It does not need to build a
new list every time.
If you modify that special object, e.g. by setting the car of it, then
compiler may ignore that and upon the next setq set the value with modified
car.

- Willem
Didier Verna
2013-10-03 08:13:46 UTC
Permalink
Post by Willem Broekema
The value that is assigned, that is the problem. That is probably a
modified literal list.
You're absolutely right. I hadn't realized it but I was doing exactly that:

http://stackoverflow.com/questions/8962909/why-does-this-function-return-a-different-value-every-time/8963438

Thanks for spotting this!
--
Resistance is futile. You will be jazzimilated.

Lisp, Jazz, Aïkido: http://www.didierverna.info
Alessio Stalla
2013-10-03 08:25:56 UTC
Permalink
Post by Didier Verna
Post by Willem Broekema
The value that is assigned, that is the problem. That is probably a
modified literal list.
http://stackoverflow.com/questions/8962909/why-does-this-function-return-a-different-value-every-time/8963438
N00b! xD

But seriously, it is hard to detect these problems when they're buried deep
in layers of code.
Post by Didier Verna
Thanks for spotting this!
--
Resistance is futile. You will be jazzimilated.
Lisp, Jazz, Aïkido: http://www.didierverna.info
--
Some gratuitous spam:

http://ripple.com <http://ripple-project.org> Ripple, social credit system
http://common-lisp.net/project/armedbear ABCL, Common Lisp on the JVM
http://code.google.com/p/tapulli my Lisp open source projects
http://www.manydesigns.com/ ManyDesigns Portofino, open source model-driven
Java web application framework
Didier Verna
2013-10-03 08:41:11 UTC
Permalink
Post by Alessio Stalla
N00b! xD
Exactly :-) Sometimes, you have your nose stuck deep in the mess and
you can't see the broader picture anymore.
--
Resistance is futile. You will be jazzimilated.

Lisp, Jazz, Aïkido: http://www.didierverna.info
Ala'a Mohammad
2013-10-03 08:20:53 UTC
Permalink
Hi,

Side question.

If you intend to change the value why do you use 'defvar' instead of
'defparameter'

Regards,

Ala'a
Post by Didier Verna
Hello,
yesterday, I fell on something extremely weird, or at least, which I
currently fail to understand. Basically, after a (defvar *var*), there
are times when (setq *var* '(0 0)) doesn't work (the previous value of
*var* remains in effect).
I cannot currently provide a minimal example because the situation
involves several levels of nested macro / function calls in code I
didn't write (*var* is solely mine though).
At first, I thought I had fallen on a compiler bug, but I get the same
behavior with at least 3 lisp implementations.
I ultimately found a workaround, consisting in using (list 0 0) instead
of '(0 0) in the assignment. I'm hoping this would be a clue to someone
here to get at least a direction for investigating...
Thanks.
--
Resistance is futile. You will be jazzimilated.
Lisp, Jazz, Aïkido: http://www.didierverna.info
Didier Verna
2013-10-03 08:45:59 UTC
Permalink
Post by Ala'a Mohammad
If you intend to change the value why do you use 'defvar' instead of
'defparameter'
In that particular case, it doesn't really matter because this
variable is always reinitialized by a function call before doing
anything with it.
--
Resistance is futile. You will be jazzimilated.

Lisp, Jazz, Aïkido: http://www.didierverna.info
Loading...