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))
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
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
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