nested push

Started by newdep, May 21, 2005, 01:57:38 AM

Previous topic - Next topic

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

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