From: Mark Carter
Subject: Comments on this function?
Date: 
Message-ID: <4356aa49$0$41143$14726298@news.sunsite.dk>
I had a go at writing a function which interleaves two lists together:

(defun conjoin (result list1 list2)
   "conjoin 2 lists. e.g. (conjoin nil '(1 2) '(3 4)) => (1 3 2 4)"
   (if (eql nil list1)
       result
     (conjoin (nconc result
		    (list (car list1))
		    (list (car list2)))
	     (cdr list1) (cdr list2))))

I'm pretty sure that there must be a better way of doing things, and 
that I'm reinventing a wheel. Any suggestions?

From: Thomas F. Burdick
Subject: Re: Comments on this function?
Date: 
Message-ID: <xcv8xwpdzje.fsf@conquest.OCF.Berkeley.EDU>
Mark Carter <··@privacy.net> writes:

> I'm pretty sure that there must be a better way of doing things, and 
> that I'm reinventing a wheel. Any suggestions?

(mapcan #'list list1 list2)

-- 
           /|_     .-----------------------.                        
         ,'  .\  / | Free Mumia Abu-Jamal! |
     ,--'    _,'   | Abolish the racist    |
    /       /      | death penalty!        |
   (   -.  |       `-----------------------'
   |     ) |                               
  (`-.  '--.)                              
   `. )----'                               
From: Mark Carter
Subject: Re: Comments on this function?
Date: 
Message-ID: <43573e07$0$41137$14726298@news.sunsite.dk>
Thomas F. Burdick wrote:
> Mark Carter <··@privacy.net> writes:
> 
> 
>>I'm pretty sure that there must be a better way of doing things, and 
>>that I'm reinventing a wheel. Any suggestions?
> 
> 
> (mapcan #'list list1 list2)
> 

Oh dear, how embarassing for me. So many mapping functions, so little 
knowledge on my part.


Many thanks.
From: Juho Snellman
Subject: Re: Comments on this function?
Date: 
Message-ID: <slrndldb18.tj.jsnell@sbz-30.cs.Helsinki.FI>
<··@privacy.net> wrote:
> I had a go at writing a function which interleaves two lists together:
> 
> (defun conjoin (result list1 list2)
>    "conjoin 2 lists. e.g. (conjoin nil '(1 2) '(3 4)) => (1 3 2 4)"
>    (if (eql nil list1)
>        result
>      (conjoin (nconc result
> 		    (list (car list1))
> 		    (list (car list2)))
> 	     (cdr list1) (cdr list2))))
> 
> I'm pretty sure that there must be a better way of doing things, and 
> that I'm reinventing a wheel. Any suggestions?

(mapcan #'list '(1 2) '(3 4))

Has slightly different semantics than your version when the lists are
of different lengths. As a bonus it'll also work with more than two
lists:

(mapcan #'list '(1 2 3) '(a b c) '(x y z))

-- 
Juho Snellman
"Premature profiling is the root of all evil."
From: Barry Margolin
Subject: Re: Comments on this function?
Date: 
Message-ID: <barmar-5BE774.17403920102005@comcast.dca.giganews.com>
In article <·························@news.sunsite.dk>,
 Mark Carter <··@privacy.net> wrote:

> I had a go at writing a function which interleaves two lists together:
> 
> (defun conjoin (result list1 list2)
>    "conjoin 2 lists. e.g. (conjoin nil '(1 2) '(3 4)) => (1 3 2 4)"
>    (if (eql nil list1)

(eql nil list1) is virtually always written as (null list1)

>        result
>      (conjoin (nconc result
> 		    (list (car list1))
> 		    (list (car list2)))
> 	     (cdr list1) (cdr list2))))

Please indent properly.  It's impossible to tell where the end of the 
NCONC is in this.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***