Visual Prolog object-oriented programming language, compiler, IDE, debugger, classes, examples, tutorials  
Prolog Development Center A/S (PDC)
discuss.visual-prolog.com
Visual Prolog Discussion forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
procedural if-then-else with a return

 
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog
View previous topic :: View next topic  
Author Message
Steve Lympany
VIP Member


Joined: 31 Mar 2001
Posts: 1563
Location: Horsham, England

PostPosted: 8 Feb 2010 17:11    Post subject: procedural if-then-else with a return Reply with quote

Hi Thomas,
Just an observation.
The following compiles without problem:

domains
    dom=one;two.
predicates
   test:(dom).
clauses
   test(DOM):-
      if DOM=one then
         RET=1
      elseif DOM=two then
         RET=2
      end if.

- the if-then-else correctly recognises all domain options to make the predicate procedural, and there is no need for a "catch-all" else statement.

However for a predicate function:


predicates
   test:(dom)->integer.
clauses
   test(DOM)=RET:-
      if DOM=one then
         RET=1
      elseif DOM=two then
         RET=2
      end if.

the compiler complains:

error c998: The variable 'RET' can be both free and bound

So it needs a final "else" to fix it:

      else
         RET=3

But maybe this is quite tricky for the compiler to resolve.
regards
Steve
Back to top
View user's profile Send private message Visit poster's website
Thomas Linder Puls
VIP Member


Joined: 28 Feb 2000
Posts: 2184
Location: Copenhagen, Denmark

PostPosted: 8 Feb 2010 19:31    Post subject: Reply with quote

Hi, Steve.

The compiler does not even attempt to make such judgements for elseif.

The reason the predicates works, while the function doesn't is that you use "RET" after the if-construction in function but not in the predicate.

Completeness analysis is made plain pattern matching using and and or:

clauses
    test(DOM) :-
       (
            DOM=one, RET=1
        or
            DOM=two, RET=2
        ),
        stdio::write(Ret).

and for pattern matching in arguments:

clauses
    test(one) :-
        RET=1,
        stdio::write(Ret).
    test(two) :-
        RET=1,
        stdio::write(Ret).


_________________
Regards Thomas Linder Puls
Prolog Development Center
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum