๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: gmane.comp.ai.prolog.swi
2 messages
2 total messages Started by Lionel Ains Fri, 12 Apr 2002 13:52
Question about the use of delete/3 for lists
#8
Author: Lionel Ains
Date: Fri, 12 Apr 2002 13:52
59 lines
1497 bytes
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.

--=_NextPart_Caramail_0010631018608724_ID
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello,

I've got a quick question about the use of delete/3
>From the SWI-Prolog manual, I though I was going to use it
to implement a cleanup predicate for a list:

The following works as I was expecting:
?- delete([a, b, c, d, a], a, Out).

Out = [b, c, d] ;

No

But, when I try to delete compounds from a list using the
following call:
?- delete([foo(a,b), foo(a,c), foo(c,a), foo(a,b),
bar(a,b)], foo(a, _), Out).

Out = [foo(a, c), foo(c, a), bar(a, b)] ;

No
I get [foo(a, c), foo(c, a), bar(a, b)], while I would have
expected: [foo(c,a), bar(a,b)].

It looks like delete internally binds my _ to c and only
deleted foo(a,c)

Can someone help on this?

Many thanks,

Lionel

______________________________________________________
Boรฎte aux lettres - Caramail - http://www.caramail.com


--=_NextPart_Caramail_0010631018608724_ID--


----------------
* To UNSUBSCRIBE, please use the HTML form at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist

or send mail to prolog-request@swi.psy.uva.nl using the Subject: "unsubscribe"
(without the quotes) and *no* message body.

** An ARCHIVE of this list is maintained at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/

Re: Question about the use of delete/3 for lists
#7
Author: Jan Wielemaker
Date: Fri, 12 Apr 2002 13:27
52 lines
1469 bytes
On Friday 12 April 2002 14:52, Lionel Ains wrote:
> Hello,
>
> I've got a quick question about the use of delete/3
> From the SWI-Prolog manual, I though I was going to use it
> to implement a cleanup predicate for a list:
>
> The following works as I was expecting:
> ?- delete([a, b, c, d, a], a, Out).
>
> Out = [b, c, d] ;
>
> No
>
> But, when I try to delete compounds from a list using the
> following call:
> ?- delete([foo(a,b), foo(a,c), foo(c,a), foo(a,b),
> bar(a,b)], foo(a, _), Out).
>
> Out = [foo(a, c), foo(c, a), bar(a, b)] ;
>
> No
> I get [foo(a, c), foo(c, a), bar(a, b)], while I would have
> expected: [foo(c,a), bar(a,b)].
>
> It looks like delete internally binds my _ to c and only
> deleted foo(a,c)
>
> Can someone help on this?

After getting wiser, my advice is to stay away from delete/3.
Use select/3, which is nice and clean semantics or write
your own delete/3 that does what you want.  There has
been discussion about this in the past, leading to quite
a few definitions of delete/3 that were all sensible given
the right point of view.

	Cheers --- Jan


----------------
* To UNSUBSCRIBE, please use the HTML form at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist

or send mail to prolog-request@swi.psy.uva.nl using the Subject: "unsubscribe"
(without the quotes) and *no* message body.

** An ARCHIVE of this list is maintained at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/

Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads