Code Comments
Programming Forum and web based access to our favorite programming groups.hi How can I use "or"? I want to do some calculations when in procedure "myPrint(A)", A is either 5 or 10. Thanks in advance LinuxMan P.S. I'm using SWI-Prolog
Post Follow-up to this messagemyPrint(A) :- ( A = 5, write(five) ; A = 10, write(ten) ). (the semicolon means "or"). but you can often do "or" just by having multiple clauses: myPrint(A) :- A = 5, write(five). myPrint(A) :- A = 10, write(ten). Is that what you are asking? -Benjamin Johnston "Linux Man" <steven_82m@hotmail.com> wrote in message news:150a16c6.0403241334.203e8b2d@posting.google.com... > hi > > How can I use "or"? I want to do some calculations when in procedure > "myPrint(A)", A is either 5 or 10. > > Thanks in advance > LinuxMan > > P.S. I'm using SWI-Prolog
Post Follow-up to this messageHi Again,
About the OR, maybe my question wasn't clear.
The program I want is: (the syntax is in Java, but I need the Prolog syntax)
if ( (A==5) || (A==10) )
{
print('Hello from the World to Benjamin');
}
I don't want to use the "print" command twice. That's I do NOT want:
myPrint(A) :- A=5, print('Hello from the World to Benjamin').
myPrint(A) :- A=10, print('Hello from the World to Benjamin').
Thanks in advance
Steve
Post Follow-up to this messageOn Thu, 24 Mar 2004, Linux Man wrote:
> Hi Again,
>
> About the OR, maybe my question wasn't clear.
> The program I want is: (the syntax is in Java, but I need the Prolog synta
x)
> if ( (A==5) || (A==10) )
> {
> print('Hello from the World to Benjamin');
> }
>
> I don't want to use the "print" command twice. That's I do NOT want:
> myPrint(A) :- A=5, print('Hello from the World to Benjamin').
> myPrint(A) :- A=10, print('Hello from the World to Benjamin').
I can understand that.
So, you could of course abstract out the differing parts into a separate
predicate (or sometimes more than one), like :
myPrint(A) :-
fiveOrTen(A),
print('Hello from the World to Benjamin').
fiveOrTen(A) :-
A = 5.
fiveOrTen(A) :-
A = 10.
(Or just
fiveOrTen( 5).
fiveOrTen(10).
for this simple example.
)
But this might sometimes get a bit unwieldy, especially if the differing
parts that were abstracted out depended on many variables.
(Because you'd have to manually pass them other in arguments to the other
predicate. No local predicates (with non-local variable access) in Prolog
:-(
)
So, we can also solve this problem like :
myPrint(A) :-
( A = 5
; A = 10
),
print('Hello from the World to Benjamin').
Does that answer your question ?
> Thanks in advance
> Steve
--
Stefan Lj
md9slj
The infinity that can be finitely expressed is not the true infinity
Post Follow-up to this messageLinux Man wrote:
> if ( (A==5) || (A==10) )
> {
> print('Hello_from_the_World_to_Benjamin'
);
> }
__myPrint(A)_:-
__________(A==5 ; a==10),
__________print('Hello_from_the_World_to
_Benjamin').
--
Best Regards,
Maurizio Colucci
Please remove the uppercase letters "S,P,A,M":
seSgPuAsMo.forever@tin.it
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.