Page 1 of 1
Stitching lists together
Posted: Fri Apr 23, 2010 5:56 pm
by cormullion
Given two lists, what's the easiest way to splice them together.
From this:
Code: Select all
(set 'a '(fred jim bob))
(set 'b '(1 2 3))
to this
... coming back to some newLISP coding after a few weeks away and I think I'm rusty...
Re: Stitching lists together
Posted: Fri Apr 23, 2010 6:15 pm
by m i c h a e l
This does the trick:
I’m sure there’s an even better way, though.
m i c h a e l
Re: Stitching lists together
Posted: Fri Apr 23, 2010 7:14 pm
by cormullion
Thanks! I've forgotten more than I thought! :)
Re: Stitching lists together
Posted: Fri Apr 23, 2010 8:53 pm
by Sammo
Another solution:
Code: Select all
(transpose (list a b))
>((fred 1) (jim 2) (bob 3))
and applying transpose again has the effect of undoing:
Code: Select all
(transpose (transpose (list a b)))
>((fred jim bob) (1 2 3))
Re: Stitching lists together
Posted: Sat Apr 24, 2010 6:18 am
by cormullion
like it!
Re: Stitching lists together
Posted: Wed Apr 28, 2010 3:22 pm
by Tim Johnson
I use this function
Code: Select all
(define (merge)(transpose (args)))
Lutz is a man of few words ...