Stitching lists together

Started by cormullion, April 23, 2010, 10:56:31 AM

Previous topic - Next topic

cormullion

Given two lists, what's the easiest way to splice them together.



From this:


(set 'a '(fred jim bob))
(set 'b '(1 2 3))


to this


((fred 1) (jim 2) (bob 3))

... coming back to some newLISP coding after a few weeks away and I think I'm rusty...

m i c h a e l

#1
This does the trick:


(map list a b)

I'm sure there's an even better way, though.



m i c h a e l

cormullion

#2
Thanks! I've forgotten more than I thought! :)

Sammo

#3
Another solution:
(transpose (list a b))
>((fred 1) (jim 2) (bob 3))

and applying transpose again has the effect of undoing:
(transpose (transpose (list a b)))
>((fred jim bob) (1 2 3))

cormullion

#4
like it!

Tim Johnson

#5
I use this function

(define (merge)(transpose (args)))

Lutz is a man of few words ...
Programmer since 1987. Unix environment.