From: Kevin Goodier
Subject: How to return every other element
Date: 
Message-ID: <MPG.f5a717915b09fc598968b@newsreader.wustl.edu>
Is there an efficient (i.e. built-in) way to return every other element 
from a list?  Suppose I have:

	'(6 9 14 18 22 26 31)

and I want:

	'(6 14 22 31)

This looks like a great case for MAPCAR, but I'm not exactly sure how to 
accomplish it.  Anyone??

------------->
     Kevin Goodier
     ····@cec.wustl.edu
     http://students.cec.wustl.edu/~bkg2/

From: Barry Margolin
Subject: Re: How to return every other element
Date: 
Message-ID: <dZ3I.8$nf2.505461@cam-news-reader1.bbnplanet.com>
In article <·························@newsreader.wustl.edu>,
Kevin Goodier <····@cec.wustl.edu> wrote:
>Is there an efficient (i.e. built-in) way to return every other element 
>from a list?  Suppose I have:
>
>	'(6 9 14 18 22 26 31)
>
>and I want:
>
>	'(6 14 22 31)

(loop for x in list by #'cddr
      collect x)

This example is on the bottom of p.720 of CLtL2.

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.
From: Rainer Joswig
Subject: Re: How to return every other element
Date: 
Message-ID: <joswig-2302981037100001@kraftbuch.lavielle.com>
In article <·························@newsreader.wustl.edu>,
····@cec.wustl.edu (Kevin Goodier) wrote:

> Is there an efficient (i.e. built-in) way to return every other element 
> from a list?  Suppose I have:
> 
>         '(6 9 14 18 22 26 31)
> 
> and I want:
> 
>         '(6 14 22 31)
> 
> This looks like a great case for MAPCAR, but I'm not exactly sure how to 
> accomplish it.  Anyone??

(loop for item in '(6 9 14 18 22 26 31) by #'cddr
      collect item)


(labels ((every-other (list)
           (if (null list)
             nil
             (cons (first list)
                   (every-other (rest (rest list)))))))
  (every-other '(6 9 14 18 22 26 31)))

-- 
http://www.lavielle.com/~joswig/