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

Define new Operators...
Hello,


I have the following code-example:


%*********************************

:- op(800, fx, if).

:- op(700, xfx, then).

:- op(300, xfy, or).

:- op(200, xfy, and).




fact(hall_wet).

fact(bathroom_dry).


if

hall_wet and bathroom_dry

then

leak_in_kitchen.

%**********************************


I don't really understand the syntax of the operator-command (op). As I read
in my book I can define new operators and the number is the predecence, the
fx, xfx... is for the tpye (infix, prefix...) and the last parameter is the
name. O.k. so far, so good.


But...


How does it really work? How knows the compiler that my defined operator
acts like an "and" and not than something else. How it is possible that I
can use "if hall_wet and bathroom_dry then leak_in_kitchen." and the "if"
works like an if and the "then" works like a then, only with these few
definition-parameters???


I hope you understand my question...


Thanks,


Tobias



Report this thread to moderator Post Follow-up to this message
Old Post
Tobias Mauderer
10-01-04 08:57 PM


Re: Define new Operators...
In message <2s5cokF1gh7qhU1@uni-berlin.de>, Tobias Mauderer
<tobimau@gmx.de> writes
>Hello,
>
>
>I have the following code-example:
>
>
>%*********************************
>
>:- op(800, fx, if).
>
>:- op(700, xfx, then).
>
>:- op(300, xfy, or).
>
>:- op(200, xfy, and).
>
>
>
>
>fact(hall_wet).
>
>fact(bathroom_dry).
>
>
>if
>
>hall_wet and bathroom_dry
>
>then
>
>leak_in_kitchen.
>
>%**********************************
>
>
>I don't really understand the syntax of the operator-command (op). As I rea
d
>in my book I can define new operators and the number is the predecence, the
>fx, xfx... is for the tpye (infix, prefix...) and the last parameter is the
>name. O.k. so far, so good.
>
>
>But...
>
>
>How does it really work? How knows the compiler that my defined operator
>acts like an "and" and not than something else. How it is possible that I
>can use "if hall_wet and bathroom_dry then leak_in_kitchen." and the "if"
>works like an if and the "then" works like a then, only with these few
>definition-parameters???

It doesn't.  Prolog has no idea what you mean by "and" and "if".  All
you have told it is the syntax, it knows nothing about the semantics.

The effect would be exactly the same if you wrote

:- op(800, fx, spade).
:- op(700, xfx, heart).
:- op(300, xfy, diamond).
:- op(200, xfy, club).

spade
hall_wet and bathroom_dry
heart
leak_in_kitchen.

That is, it would parse this as

spade( heart( club( hall_wet, bathroom_dry) leak_in_kitchen)).

Nick
--
Nick Wedd    nick@maproom.co.uk

Report this thread to moderator Post Follow-up to this message
Old Post
Nick Wedd
10-12-04 01:56 PM


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 05:41 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.