Re: trying to flatten a list



Anders Lindén wrote:
>
> whats the difference between
> not(A) :- A,!,fail;true.
> and
> not(A) :- !,A,fail;true.

With

not(A) :- A, !, fail ; true.

a goal not(P) will call P. If P succeeds, the cut
commits to this arm of the disjunction, and then
the clause fails.

If P fails, Prolog backtracks into the second arm
of the disjunction which succeeds.

With

not(A) :- !, A, fail ; true.

a goal not(P) starts by committing to the first
disjunct. Then either P succeeds and we go on
to fail, or P fails and so not(P) fails. That
is, this definition of not/1 will always fail!

-- Ralph

PS What is it with Prolog programmers and bad code
layout? Adding a bit of whitespace doesn't cost
that much extra effort...

.



Relevant Pages

  • Re: Strange fopen error
    ... First time I open the file with fopen, it succeeds. ... file, it fails. ...   if{ ... I guess it's the glfw lib that changes the working directory. ...
    (comp.sys.mac.programmer.help)
  • Re: .Net (C#) Service Fails To Start
    ... Interesting technique - but when my code fails, it does not seem to even get that far, and when it succeeds, I have no need to debug it, and I cannot predict when it will fail. ... I checked and there are no dependencies marked for the service. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: renaming a table
    ... > if it succeeds, truncate all rows in your target rable, copy the inbox rows ... If I do that and the download fails for some reason, ...
    (microsoft.public.sqlserver.ce)
  • Re: [PATCH 05/11] sysfs: sysfs_chmod_file handle multiple superblocks
    ... instead of failing half way through but given the interface of ... The latter never fails and the former should always ... succeed if inode_change_oksucceeds never fails ... struct iattr * sd_iattr; ...
    (Linux-Kernel)
  • Re: set of sets
    ... the add succeeds ... the remove fails eventually not calling hash. ... Is this fast as with lists? ...
    (comp.lang.python)