From: William James
Subject: Re: Assoc to retrieve all associations?
Date: 
Message-ID: <gndbes0p2m@enews4.newsguy.com>
Francogrex wrote:

> Assoc:
> Args: (ITEM ALIST &KEY (TEST '#'EQL) TEST-NOT (KEY '#'IDENTITY))
> Returns the first pair in ALIST whose car is equal (in the sense of
> TEST) to
> ITEM.  Returns NIL if no such pair exists...
> 
> Suppose we have this simple example:
> : (setf my-list '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen
> 7)))
> : (assoc 'paper my-list)
> : (PAPER 2)
> 
> OK but is there any way/function, maybe a variation of assoc, to get a
> list of all pairs in my-list with 'paper in them (instead of just the
> 1st ocurrence) without resorting to loops? Thanks

user=> (filter #(= 'paper (first %)) mylist)
 --> ((paper 2) (paper 3) (paper 4))

From: Marco Antoniotti
Subject: Re: Assoc to retrieve all associations?
Date: 
Message-ID: <94c3c4c2-ef4b-4965-89a6-33bdac70599b@s20g2000yqh.googlegroups.com>
On Feb 17, 4:38 am, "William James" <·········@yahoo.com> wrote:
> Francogrex wrote:
> > Assoc:
> > Args: (ITEM ALIST &KEY (TEST '#'EQL) TEST-NOT (KEY '#'IDENTITY))
> > Returns the first pair in ALIST whose car is equal (in the sense of
> > TEST) to
> > ITEM.  Returns NIL if no such pair exists...
>
> > Suppose we have this simple example:
> > : (setf my-list '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen
> > 7)))
> > : (assoc 'paper my-list)
> > : (PAPER 2)
>
> > OK but is there any way/function, maybe a variation of assoc, to get a
> > list of all pairs in my-list with 'paper in them (instead of just the
> > 1st ocurrence) without resorting to loops? Thanks
>
> user=> (filter #(= 'paper (first %)) mylist)
>  --> ((paper 2) (paper 3) (paper 4))

That ain't Ruby.

Plus CL is

   (select 'paper mylist :key 'first)

Cheers
--
Marco
From: John Thingstad
Subject: Re: Assoc to retrieve all associations?
Date: 
Message-ID: <op.uphwwxsgut4oq5@pandora.alfanett.no>
P� Tue, 17 Feb 2009 09:58:16 +0100, skrev Marco Antoniotti  
<·······@gmail.com>:

> On Feb 17, 4:38�am, "William James" <·········@yahoo.com> wrote:
>> Francogrex wrote:
>> > Assoc:
>> > Args: (ITEM ALIST &KEY (TEST '#'EQL) TEST-NOT (KEY '#'IDENTITY))
>> > Returns the first pair in ALIST whose car is equal (in the sense of
>> > TEST) to
>> > ITEM. �Returns NIL if no such pair exists...
>>
>> > Suppose we have this simple example:
>> > : (setf my-list '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen
>> > 7)))
>> > : (assoc 'paper my-list)
>> > : (PAPER 2)
>>
>> > OK but is there any way/function, maybe a variation of assoc, to get a
>> > list of all pairs in my-list with 'paper in them (instead of just the
>> > 1st ocurrence) without resorting to loops? Thanks
>>
>> user=> (filter #(= 'paper (first %)) mylist)
>> �--> ((paper 2) (paper 3) (paper 4))
>
> That ain't Ruby.
>
> Plus CL is
>
>    (select 'paper mylist :key 'first)
>
> Cheers
> --
> Marco
>

There is no select..

(remove-if-not 'paper mylist :key #'first)

--------------
John Thingstad
From: Marco Antoniotti
Subject: Re: Assoc to retrieve all associations?
Date: 
Message-ID: <8064c975-d33f-4446-94b7-c74cfaf3f085@r41g2000yqm.googlegroups.com>
On Feb 17, 1:27 pm, "John Thingstad" <·······@online.no> wrote:
> På Tue, 17 Feb 2009 09:58:16 +0100, skrev Marco Antoniotti  
> <·······@gmail.com>:
>
>
>
> > On Feb 17, 4:38 am, "William James" <·········@yahoo.com> wrote:
> >> Francogrex wrote:
> >> > Assoc:
> >> > Args: (ITEM ALIST &KEY (TEST '#'EQL) TEST-NOT (KEY '#'IDENTITY))
> >> > Returns the first pair in ALIST whose car is equal (in the sense of
> >> > TEST) to
> >> > ITEM.  Returns NIL if no such pair exists...
>
> >> > Suppose we have this simple example:
> >> > : (setf my-list '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen
> >> > 7)))
> >> > : (assoc 'paper my-list)
> >> > : (PAPER 2)
>
> >> > OK but is there any way/function, maybe a variation of assoc, to get a
> >> > list of all pairs in my-list with 'paper in them (instead of just the
> >> > 1st ocurrence) without resorting to loops? Thanks
>
> >> user=> (filter #(= 'paper (first %)) mylist)
> >>  --> ((paper 2) (paper 3) (paper 4))
>
> > That ain't Ruby.
>
> > Plus CL is
>
> >    (select 'paper mylist :key 'first)
>
> > Cheers
> > --
> > Marco
>
> There is no select..
>
> (remove-if-not 'paper mylist :key #'first)
>

Come on! Gimme a hand here!  :)

Cheers
--
Marco