nondestructive push

Started by Dmi, November 09, 2005, 02:49:02 PM

Previous topic - Next topic

Dmi

How can I construct a function, that nondestructive appends an element to a list and return modified list?

I wrote so:
(define (print-ln) (print (join (append (args) (list "n")))))
But the idea is so usual, that I suspect, there is more fine way, without using

(append lst (list one-element))



... I use 'print-ln' insead of println under windows to handle unix-generated text files.
WBR, Dmi

pjot

#1

(define (mypush) (flat (append (args))))

> (set 'lst (mypush 1 2 3))
(1 2 3)
> (mypush lst 4)
(1 2 3 4)


...or is this not what you want?



Peter

newdep

#2
Thats destructive, DMI ment non-destrutive ;-)
-- (define? (Cornflakes))

pjot

#3
It's non destructive:



> (set 'lst (mypush 1 2 3))
(1 2 3)
> (mypush lst 4)
(1 2 3 4)
> (println lst)
(1 2 3)

newdep

#4
Its surly is ...:)
-- (define? (Cornflakes))