nested push

Q&A's, tips, howto's
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

nested push

Post by newdep »

Hi Lutz,

Is it possible to enhance 'push with the option of a nested list push?

Example ->

> (setq test '( (one "line") (two "lines") ))
((one "line") (two "lines"))

;; this looks logic but is not possible.. ->

> (push "quotes" (test 0) -1)
"quotes"
> test
((one "line") (two "lines"))
>

> (push "quotes" (nth 0 test) -1)
"quotes"
> test
((one "line") (two "lines"))
>


;; instead this is how it is done now...

> (push "quotes" test '(0 -1))
"quotes"
> test
((one "line" "quotes") (two "lines"))
>


So actualy "what is logic to use?" Im was just programming ahead and
thought my guess was logic though it was not :) I understand the relation
between 'ref and 'push though the above would make push even more
flexible in total. The same goes for 'pop.

Norman.
-- (define? (Cornflakes))

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

Post by Lutz »

Any expression like (nth 1 lst) will not return a reference to that part of a list, but a copy of that sublist. For that reason there is no possibility to implement this. BTW you can make your push slightly more elegant omitting the parenthesis around the indices:

(push "quotes" test 0 1)

But I guess you knew that (but for the newbies else reading this),

Lutz

Locked