Defining Operators in Prolog

By defining two operators in Prolog:

op(100, xfy, #).
op(100, fy, ϴ).

      

what is expression

a # ϴ b # c

      

equivalent to?

a # ϴ (b # c)

      

or maybe

a # ((ϴ b) # c)

      

And why?

+3


source to share


1 answer


You can see what Prolog will do with it with write_canonical/1

:

?- op(100,xfy,#).
true.

?- op(100,fy,@).
true.

?- write_canonical(a # @ b # c).
#(a,@(#(b,c)))
true.

      

So it seems that your first guesses are correct. The interpretation a # @ b # c

is equal a # (@(b # c))

. A key comment in the documentation forop/3

pertaining to this:



f

indicates the position of the functor, while x

and y

indicate the position of the arguments. y

should be interpreted as "at this position there must be a term with a priority less than or equal to the priority of the functor." For the x

priority of the argument must be strictly lower.

Usage fy

results in grouping of priorities @(b # c)

instead of (@b) # c

.

+4


source







All Articles