Dynamic list values

Started by pjot, October 15, 2006, 10:27:54 AM

Previous topic - Next topic

pjot

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

Lutz

#1
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

pjot

#2
Thanks, exactly what I was looking for!!



Peter