From: Marco Antoniotti
Subject: Re: Assoc to retrieve all associations?
Date: 
Message-ID: <54bf2682-7676-4ab7-b693-849c73cdaa6c@j1g2000yqi.googlegroups.com>
On Feb 13, 5:38 pm, Francogrex <······@grex.org> 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

(remove 'paper '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen
7))
        :test (complement 'eql)
        :key 'first)

Cheers
--
Marco

From: Slobodan Blazeski
Subject: Re: Assoc to retrieve all associations?
Date: 
Message-ID: <06a478e3-d9a7-4400-916f-a57c30d6d59b@e18g2000yqo.googlegroups.com>
On Feb 13, 6:31 pm, Marco Antoniotti <·······@gmail.com> wrote:
> On Feb 13, 5:38 pm, Francogrex <······@grex.org> 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
>
> (remove 'paper '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen
> 7))
>         :test (complement 'eql)
>         :key 'first)
>
Very nice.

bobi
> Cheers
> --
> Marco
From: Rob Warnock
Subject: Re: Assoc to retrieve all associations?
Date: 
Message-ID: <9MadnTQRn51ARgXUnZ2dnUVZ_jCdnZ2d@speakeasy.net>
Slobodan Blazeski  <·················@gmail.com> wrote:
+---------------
| Marco Antoniotti <·······@gmail.com> wrote:
| > (remove 'paper '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen 7))
| >         :test (complement 'eql)
| >         :key 'first)
|
| Very nice.
+---------------

One tiny quibble: (COMPLEMENT 'EQL) won't work [at least, not portably]
since COMPLEMENT takes a function, not a function designator. You need
to write it as (COMPLEMENT #'EQL). On the other hand, :TEST-NOT [1]
does take a function designator and thus this works portably:

    > (remove 'paper '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen 7))
	      :test-not 'eql :key 'first)

    ((PAPER 2) (PAPER 3) (PAPER 4))
    > 


-Rob

[1] Which I stubbornly persist in using despite its "deprecated" status! ;-}

-----
Rob Warnock			<····@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607
From: Marco Antoniotti
Subject: Re: Assoc to retrieve all associations?
Date: 
Message-ID: <5584147b-d88a-4c4c-a304-6388512b6fb9@v39g2000yqm.googlegroups.com>
On Feb 16, 4:22 am, ····@rpw3.org (Rob Warnock) wrote:
> Slobodan Blazeski  <·················@gmail.com> wrote:
> +---------------
> | Marco Antoniotti <·······@gmail.com> wrote:
> | > (remove 'paper '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen 7))
> | >         :test (complement 'eql)
> | >         :key 'first)
> |
> | Very nice.
> +---------------
>
> One tiny quibble: (COMPLEMENT 'EQL) won't work [at least, not portably]
> since COMPLEMENT takes a function, not a function designator. You need
> to write it as (COMPLEMENT #'EQL). On the other hand, :TEST-NOT [1]
> does take a function designator and thus this works portably:
>
>     > (remove 'paper '((test 1) (paper 2) (pen 2) (paper 3) (paper 4) (pen 7))
>               :test-not 'eql :key 'first)
>
>     ((PAPER 2) (PAPER 3) (PAPER 4))
>     >
>
> -Rob
>
> [1] Which I stubbornly persist in using despite its "deprecated" status! ;-}

Good point! (LW is forgiving on COMPLEMENT.)  But you see why I used
COMPLEMENT and not :TEST-NOT.

Cheers
--
Marco





>
> -----
> Rob Warnock                     <····@rpw3.org>
> 627 26th Avenue                 <URL:http://rpw3.org/>
> San Mateo, CA 94403             (650)572-2607