Search code examples
lambdaprologexponentiationiso-prologprolog-setof

What is the Prolog operator `^` ("caret")?


What is the Prolog operator ^ ?

Looking at The Prolog Built-in Directive op gives a list of the built-in operators.

I see

  • ** is exponentiation
  • /\ is or

but what is ^ ?

Each of the three current answers are of value and I learned something:

  • Roy for the book
  • false for the examples
  • I accepted the answer by CapelliC because it made clear that ^/2 has multiple meanings
    depending on context which instantly cleared up my confusion.

Solution

  • In Prolog, most symbols can be used 'uninterpreted', at syntactic level, in particular after an op/3 declaration, any atom can be used as operator. Then you can use, for instance, ^/2 as a function constructor for a domain specific language (a DSL), with a semantic specified from your rules.

    Is SWI-Prolog (or more generally in ISO Prolog), current_op/3 gives you information about declared operators:

    ?- current_op(X,Y,^).
    X = 200,
    Y = xfy. 
    

    That said, any Prolog implementing setof/3 is expected to interpret ^/2 as a quantification specifier, when put to decorate the 2nd argument. As well, any Prolog implementing is/2 is expected to interpret ^/2 as exponentiation, when occurring on the right side of the is/2 expression.