Question/request?

Pondering the philosophy behind the language
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Question/request?

Post by newdep »

Hi Lutz,

Im wondering if the following is possible in newlisp...
I could not find a function that does this..

i.e.

I have a list -> (setq A '( (+ x 1) (- x 2) ))

Now I want to COPY/MIRROR that list to B..
But in this manner that everything that is changed inside List A also will be changed in list B.

This means that list B is a Symbolic-Link/Mirror to list A..
everything changes in A changes in B..
(not reverse nessesarly)


>(setq A '( (+ x 1) (- x 2) ))
( (+ x 1) (- x 2) )

>(mirror A B)
( (+ x 1) (- x 2) )

> B
( (+ x 1) (- x 2) )

>(pop A 0)
( (- x 2) )

> B
( (- x 2) )



Norman.
-- (define? (Cornflakes))

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

Post by Lutz »

as contexts are passed by reference you could do the following:

Code: Select all

> (set 'A:var '((+ x 1) (- x 2)))
((+ x 1) (- x 2))
> (set 'B A)
A
> A:var
((+ x 1) (- x 2))
> B:Var
nil
> (pop A:var)
(+ x 1)
> B:var
((- x 2))
> 
Lutz

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post by newdep »

aaaaaa look... I realy must get starting on contexts now..because its
something i never use inside newlisp... Great example...thanks!
-- (define? (Cornflakes))

Locked