Re: removing items from a nested list.




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.

.



Relevant Pages

  • Re: removing items from a nested list.
    ... wooks wrote: ... the language. ... rember*/3 produces a list with all occurrences of the 1st term removed ... from the nested list provided in the 2nd tem. ...
    (comp.lang.prolog)
  • RE: WinXP Pro - cannot get rid of language .bin files in temp folder
    ... How do I get rid of them permanently? ... I have installed WinXP Pro SP2 and used the Files and Settings utility to ... But now I see 25 ".bin" files in each user's temp folder, ... I have gone to Regional and Language Options in Control Panel ... ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: OWLS measurement
    ... I helped you get rid of the problem ... >> Dirk Vdm ... Just wait until we speak the same language. ... When you find a technical (engineering, ...
    (sci.physics.relativity)
  • Re: Overloading of the unary ++ operator in VB.net
    ... Is there any way can to get rid of this error? ... incrementation "by one" differently. ... Any suggestion? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Development environments
    ... > I'm looking to getting into programming for Linux. ... Basic is not a very nice language. ... Perhaps you'll go back to Basic again, but getting rid ... The problem with the world is stupidity. ...
    (comp.os.linux.development.apps)