Page 1 of 1

unexpected setq behavior with contexts ?

Posted: Sun Sep 21, 2008 4:31 pm
by dave_f
In the code below, the version with "set" in line 5 produces (Second First) as a list of contexts. This was what I expected.

The version with "setq" produced (First First), which was a surprise. Why is this?

thanks a lot,
dave_f
newLISP v.9.9.2 , Mac OS 10.5.5 Intel

Code: Select all

(context 'CTX)
(context 'MAIN)
(setq ctx-names '(First Second))
(dolist (ctx-name ctx-names)
 	(set 'new-ctx (new CTX ctx-name) ) ; this works as I expected
;  (setq new-ctx (new CTX ctx-name))  ; this does not work as I expected
	(push new-ctx contexts)  )
(println "context list is " contexts) 

Posted: Sun Sep 21, 2008 5:28 pm
by m i c h a e l
Dave,

This is because the second time through the iteration of dolist, ctx-name will be the context First:

Code: Select all

> (define CTX:CTX)
nil
> (setq new-ctx (new CTX 'First))
First
> new-ctx
First
> (context? new-ctx)
true
> (setq new-ctx (new CTX 'Second))
Second
> new-ctx
First
> _
m i c h a e l

Posted: Sun Sep 21, 2008 5:39 pm
by Lutz
It should produce (Second First) both times and does it in 9.4.5

This is a bug introduced in 9.9.2 and is fixed in 9.9.4.