[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: if

From: Calum Grant
Subject: RE: if
Date: Mon, 29 Jan 2001 14:37:20 -0000

That's not really specific to GNU, but I'll try to answer.

There actually are "if" predicates in Prolog, and alternative branches of
execution can be taken conditionally.  The syntax is just a little different
and problems tend to be formulated differently.  e.g. in an imperative

                if(n=1) return "one"
                else if(n=2) return "two"

while in Prolog,

        printnum(1, one).
        printnum(2, two).

By default, every "branch" of the printnum predicate is taken, so
printnum(N, M) would yield two answers: N=1, M=one, N=2, M=two.  However if
you call printnum(2, M), you would just get M=two.  The first branch is not
taken, since the condition N=1 fails.

printnum can also be rewritten as

        printnum(N, M) :- N=1, M=one; N=2, M=two.

which makes it even more clear what the conditions are (N=1 or N=2).

  Calum Grant - address@hidden - 01223 569700

The Information contained in this e-mail message is intended only for
the individuals named above. If you are not the intended recipient,
you should be aware that any dissemination, distribution, forwarding
or other duplication of this communication is strictly prohibited.
The views expressed in this e-mail are those of the individual
author and not necessarily those of Envisional Software Solutions Ltd.
Prior to taking any action based upon this e-mail message you should
seek appropriate confirmation of its authenticity. If you have
received this e-mail in error, please notify the sender immediately.

> -----Original Message-----
> From: address@hidden [mailto:address@hidden
> Behalf Of Eduardo Damasio da Costa
> Sent: Monday, January 29, 2001 1:20 PM
> To: address@hidden
> Subject: if
> Hello,
> I am new to prolog and I am surprised apparently there is no "if"
> predicate.
> If, for example, we should use a set of facts and rules in
> particular  situation and another set of  facts and rules in an
> other situation, how can we implement this
> typical if situation in prolog?
> Thanks in advance,
> Eduardo Costa
> _______________________________________________
> Users-prolog mailing list
> address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]