2

I need to define a new operator that associates in the following way

 (1 newop 2) / (2 newop) / a 

The parenthesis were just used to give an understanding of the associativity of the new op

So.

:- op(A, B, newop).

Which would be the values for A and B.

Thanks in advance.

false
  • 10,264
  • 13
  • 101
  • 209
Alessandroempire
  • 1,640
  • 4
  • 31
  • 54

2 Answers2

4

What you want is that newop serves both as an infix operator as in (1 newop 2) and as a postfix operator as in (2 newop).

This is impossible in ISO Prolog. In subclause 6.3.4.3 of ISO/IEC 13211-1:1995 it is stated:

There shall not be an infix and a postfix operator with the same name.

That said, there are implementations that still permit this. However, be aware that such implementations ofter differ in subtle ways.

false
  • 10,264
  • 13
  • 101
  • 209
0

infix operator: xfx

precende should be higher than "/"

precende for / is 400

 :- op (300, xfx, newop).
Alessandroempire
  • 1,640
  • 4
  • 31
  • 54