logo       

Re: I can do with CUT: msg#01604

Subject: Re: I can do with CUT
          I have an urgent doubt.

Buy or borrow a book, such as Clocksin & Mellish.

        For example when I ask to prolog 
            
          ?- member( 3, [1,2,3]). 
          Yes 
            
          Is there any system variable associated with the prolog answer "Yes" 
or "No" ??? 
            
What is a system variable?
In an internationalised Prolog there will certainly be a fact
someone in a module that says "if a top level query that binds no
variables succeeds the thing to print is 'Yes'", which can be
changed as part of localisation.

          I have this doubt because I want to use the answer in programs
        (e.g. if answer=Yes then ....)
              
This shows that you literally do not know the first thing about Prolog.
Prolog queries DO NOT RETURN ANSWERS.  (This is relational programming,
not functional programming).  They either FAIL or they SUCCEED (possibly
binding some variables).  Goals are combined using operators like

        G1 , G2         G1 and_then G2
        G1 ; G2         G1 or_else G2
        G1 -> G2 ; G3   if G1 then G2 else G3
          
But this success (with binding) or failure is ALL THE ANSWER THERE IS
(or needs to be).

        I know that is possible with : 
        The goal member(3,[1,2,3]) succeeds and you can use that in a 
        conjunction or in an if-then-else, as in 
        
                    member(3, [1,2,3]), writeln('3 is a member of [1,2,3]')
        
        or 
        
                (   member(3, [1,2,3]) -> 
                    writeln(success) 
                ;
                    writeln(failure) 
                ) 
        
        but I need to Know how I can do with CUT.

Do *what* with cut?  What do you think "->" is?



<Prev in Thread] Current Thread [Next in Thread>