unexpected setq behavior with contexts ?

Q&A's, tips, howto's
Locked
dave_f
Posts: 8
Joined: Sun Nov 11, 2007 2:40 am
Location: Eugene, Oregon USA

unexpected setq behavior with contexts ?

Post 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) 

m i c h a e l
Posts: 394
Joined: Wed Apr 26, 2006 3:37 am
Location: Oregon, USA
Contact:

Post 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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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.

Locked