Page 1 of 1

Dynamic list values

Posted: Sun Oct 15, 2006 5:27 pm
by pjot
Hi,

I have the following code:

Code: Select all

(set 'a 0)
(set 'b '(0 1 2 3 4 a))
Is there a way to update the 'a' in this list dynamically? Meaning:
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

Posted: Sun Oct 15, 2006 5:51 pm
by Lutz
You could use expand:

Code: Select all

(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

Posted: Sun Oct 15, 2006 6:49 pm
by pjot
Thanks, exactly what I was looking for!!

Peter