1

I want to quickly create a structure in Picat. But the components of the structure should be evaluated when creating the structure. So far I tried, which gives me a structure when the components are already constants:

Picat 2.0b5, (C) picat-lang.org, 2013-2016.

Picat> X = $point(2,3).
X = point(2,3)
yes

But the following doesn't work, i.e. components that should be evaluated. I am expecting as a result X = point(3,12), but it doesn't give this result:

Picat> X = $point(1+2,3*4).
X = point(1 + 2,3 * 4)
yes

What is the shortest way to do that? It seems that the Picat ($)/1 operator is like lisp quote operator and it prevents Picat evaluation. What remains is Prolog unification. Here are some examples of Prolog unification in Picat:

Picat> $point(X,Y) = $point(1+2,3*4).
X = 1 + 2
Y = 3 * 4
yes

Picat> $point(X+Y,Z) = $point(1+2,3*4).
X = 1
Y = 2
Z = 3 * 4
yes

Picat> $X = $point(1+2,3*4).           
X = point(1 + 2,3 * 4)
yes

As in Prolog expressions such as 1+2 and 3*4 are not evaluated inside ($)/1. Maybe its impossible to have evaluating constructors in Picat, similarly they are not found in standard Prolog at the moment.

1 Answers1

3

Try this:

Picat> X = new_struct(point, [1+2,3*4]). 
X = point(3,12)
yes

It's another way to create structures in Picat. With new_struct you could create a structure passing as first argument the name of the structure that you would like to create and as second argument either an integer (that will be the number of fields of the structure) or a list. In the latter case the fields of the structure will be the elements of the list.

Even I can't understand why expressions are not evaluated before the creation of point. If I'm not wrong in the book Constraint solving with Picat is said that arguments are completely evaluated before calls are evaluated.

Mark
  • 399
  • 4
  • 12