Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Logical Or
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

Report this thread to moderator Post Follow-up to this message
Old Post
Linux Man
03-27-04 05:11 AM


Re: Logical Or
myPrint(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



Report this thread to moderator Post Follow-up to this message
Old Post
Benjamin Johnston
03-27-04 05:11 AM


Re: Logical Or
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 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

Report this thread to moderator Post Follow-up to this message
Old Post
Linux Man
03-27-04 05:11 AM


Re: Logical Or
On 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

Report this thread to moderator Post Follow-up to this message
Old Post
Stefan Ljungstrand
03-27-04 05:11 AM


Re: Logical Or
Yes Stefan, Thanks a lot for your good answer.

Report this thread to moderator Post Follow-up to this message
Old Post
Linux Man
03-27-04 05:11 AM


Re: Logical Or
Linux 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

Report this thread to moderator Post Follow-up to this message
Old Post
seguso
03-29-04 03:29 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 09:06 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.