newLISP Fan Club

Forum => Anything else we might add? => Topic started by: pjot on October 15, 2006, 10:27:54 AM

Title: Dynamic list values
Post by: pjot on October 15, 2006, 10:27:54 AM
Hi,



I have the following code:



(set 'a 0)
(set 'b '(0 1 2 3 4 a))


Is there a way to update the 'a' in this list dynamically? Meaning:


Quote
b

(0 1 2 3 4 0)


So, during initialization of 'b, the list will have assigned the value of 'a, instead of the symbol 'a itself.



Can this be done without tricks like (push) or (nth-set)? A similar thing is possible with an array, but is it possible with lists also?



Peter
Title:
Post by: Lutz on October 15, 2006, 10:51:16 AM
You could use expand:


(set 'L '(1 a 3 4 b 6))
(expand L '((a 2) (b 5))
L => (1 2 3 4 5 6)

; or if 'a' and 'b' are already set previously:

(expand L 'a 'b)


The first method is nice because it treats 'a' and 'b' as local variables similar to 'let'



Lutz
Title:
Post by: pjot on October 15, 2006, 11:49:07 AM
Thanks, exactly what I was looking for!!



Peter