Nathan Conklin (Nathan.Conklin@VT.EDU)
Tue, 25 Apr 2000 01:35:45 -0400
Message-ID: <200004250535.BAA11125@e115101.vtacs.com> Date: Tue, 25 Apr 2000 01:35:45 -0400 From: Nathan Conklin <Nathan.Conklin@VT.EDU> Subject: Re: [CS3304_1381] Help with cut
>
> How can I slim down the answers I get returned from a predicate to 1? For
> example, term([2,times,3,times,4],N). returns all of
> N = [24|1] ;
> N = [[24|1], 1] ;
> N = [[24|1], []] ;
> N = [6|1] ;
> N = [[6|1], 1] ;
> N = [[6|1], [times, 4]] ;
> N = [2|1] ;
> N = [[2|1], [times, 3, times, 4]] ;
>
> I just want the first answer. I'm pretty sure I need to use cut(!) but
> the all documentation I've been able to find on its use is pretty
> slim. Has anyone used it successfully, and could you please post a crash
> course on it?
>
Using cut will probably not be want you want in most cases. This is
because you want the backtracking mechanism of Prolog to help out. What I
suggest doing is implementing your OR conditions similar to:
if(cond)
pred1;
else
pred2;
(cond,pred1);
(not(cond),pred2).
I have found this to help so that a predicate returns only one value.
Then, you will need to find each the predicates that you can apply this to.
-- Nathan Conklin Nathan.Conklin@vt.edu 540-953-2254
This archive was generated by hypermail 2.0b3 on Tue Apr 25 2000 - 01:35:51 EDT