Subject: RE: [SWIPL] if then else

From: "Douglas R. Miles" <[email-masked]>
Date: Tue, 19 Dec 2000 10:36:02 -0800

From section 3.7 of the SWI manual 

+Condition *-> +Action ; +Else
This construct implements the so-called `soft-cut'. The control is defined
as follows: If Condition succeeds at least once, the semantics is the same
as (Condition, Action). If Condition does not succeed, the semantics is that
of (Condition, Else). In other words, If Condition succeeds at least once,
simply behave as the conjunction of Condition and Action, otherwise execute
Else. 

+Condition -> +Action
If-then and If-Then-Else. The ->/2 construct commits to the choices made at
its left-hand side, destroying choice-points created inside the clause (by
;/2), or by goals called by this clause. Unlike !/0, the choicepoint of the
predicate as a whole (due to multiple clauses) is not destroyed. The
combination ;/2 and ->/2 is defines as: 

If -> Then; _Else :- If, !, Then.
If -> _Then; Else :- !, Else.
If -> Then :- If, !, Then.

Note that the operator precedence relation between ; and -> ensure If ->
Then ; Else is actually a term of the form ;(->(If, Then), Else). The first
two clauses belong to the definition of ;/2), while only the last defines
->/2. 

On that note I tend to personally use allot of (()) around things since i
never want anything left to chance of some preexisting operator precedence
states..

For example

      give_the_test,
      	(
      		( grade_the_test ; accept_bribe )
				->
      			( write('the test passed'),nl)
	      	 	; 
      			( write('the test failed'),nl)
      	)

-----Original Message-----
From: Andre Araujo [mailto:[email-masked]]
Sent: Tuesday, December 19, 2000 6:29 AM
To: [email-masked]
Subject: [SWIPL] if then else

Hi!

How do you create an in then else sructure?

Thanks!

----------------
* To UNSUBSCRIBE, please use the HTML form at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/index.html#mailinglist

or send mail to [email-masked] using the 
Subject: "unsubscribe"
(without the quotes) and *no* message body.

** An ARCHIVE of this list is maintained at

    http://www.swi.psy.uva.nl/projects/SWI-Prolog/mailinglist/archive/