Re: removing items from a nested list.
- From: "wooks" <wookiz@xxxxxxxxxxx>
- Date: 5 Feb 2006 14:09:37 -0800
Bart Demoen wrote:
wooks wrote:
I am translating the Little Schemer into Prolog as a means of learning
the language.
rember*/3 produces a list with all occurrences of the 1st term removed
from the nested list provided in the 2nd tem.
rember*(Item,[],[]).
rember*(Item,[[Head]|Tail], Result) :-
rember*(Item,Head,Result),
rember*(Item,Tail,Result).
rember*(Item, [Item|Tail], Result) :-
rember*(Item,Tail,Result).
rember*(Item,[Head|Tail], Result) :-
rember*(Item,Tail,Result).
Others will help you with semantics, let me say something about syntax:
rember*(Item,[],[]).
is syntactically the same to Prolog as
*(rember, (Item,[],[])).
so the predicate you are really defining here is */2; it is allowed, but
perhaps not what you want. You can check this by the query (and result):
?- *(X,Y).
X = rember
Y = _G245, [], []
It might be good to write
'rember*'(Item,[],[]).
or get rid of the * completely.
Cheers
Bart Demoen
I have got rid of the * . Have also experimented wit the 2nd rule. Same
result.
.
- Follow-Ups:
- Re: removing items from a nested list.
- From: Bart Demoen
- Re: removing items from a nested list.
- References:
- removing items from a nested list.
- From: wooks
- Re: removing items from a nested list.
- From: Bart Demoen
- removing items from a nested list.
- Prev by Date: Re: removing items from a nested list.
- Next by Date: Re: Development Methodology
- Previous by thread: Re: removing items from a nested list.
- Next by thread: Re: removing items from a nested list.
- Index(es):
Relevant Pages
|