Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageIn 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.