Module func

This module provides functions on tagged structures and otherwise Prolog terms. Like already with the tagged structures itself, no new Prolog term category is introduced and we stay complete in the data model of the ISO core standard. Further, the translation is such that head side conditions are added to the end of a Prolog clause.

Examples:
?- P = point{x:1,y:2}, X = P.x, Y = P.y.
X = 1, Y = 2
?- P = [1,2], V = P.K.
V = 1, K = x ;
V = 2, K = y

After importing the module a dot notation by the operator ('.')/2 will be available to the importing module. The operator can be used to access tagged structure fields, JSON object fields and JSON array elements anywhere inside the head or the body of a Prolog clause. The operator will be replaced through the function expansion framework.

Examples:
?- D = {"x":1,"y":2}.dist().
D = 2.23606797749979
?- D = point{x:1,y:2}.offset(3,4).dist().
D = 7.211102550927978

The operator ('.')/2 can be also used to perform a couple of field operations. Among the field operations we find get(K), which will return the field value. For a non-existing field the field op-eration will not throw an exception and fail instead. Further field operations include put(D) and put(K,V) to set multiple respectively a single key values at once.

Finally the operator ('.')/2 can be also used to invoke arbitrary arity functions. To disambiguate between a field access and a zero argument function invocation the module a unit notation by the operator (())/1. Arbitrary arity function definitions can be done by the further operator (:=)/2. Our translation is Pythonesk, the self is placed in the first argument.

The following expansions for functions on tagged structures are provided:

D.F:
This rest expansion replaces a dot notation D.F where F is a variable or atomic by a side condition to access the field F.
D.get(K):
D.put(E):
D.put(K,V):
This rest expansion replaces a dot notation D.get(K), D.put(E) respectively D.put(K,V) by a side condition to perform a field operation get/3, put/3 respectively put/4.
D.F():
D.F(X1, .., Xn):
This rest expansion replaces a dot notation D.F respectively D.F(X1, .., Xn) by a side condition to invoke the definition of F/0 respectively F/n.
D.F() := X:
D.F(X1, .., Xn) := X:
This term expansion replaces a dot notation D.F() respectively D.F(X1, .., Xn) by a clause head with result X making up a definition for F/0 respectively F/n.

Comments