0

What is the definition of the symbol "=>" in Picat and how do you read it ? Is it an implication ? I have trouble to understand it since there seems to be no informations about it in the manual nor in the book.

%example using "=>"
main => 
 A = true, 
 B = true,
 C = function(A,B),
 predicate(A,B).
 
function(true,true) = R => R =  true.
predicate(true,true) => true.

How would you describe the meaning of "=>" in the previous example ? Is it just something syntactically required, such as "{" after the declaration of a method in Java, or has a deeper meaning ?

false
  • 10,264
  • 13
  • 101
  • 209
  • I found out, via https://www.cis.upenn.edu/~matuszek/Concise%20Guides/Concise%20Prolog.html, that ":-" in prolog is a clause and is read as "if". Since "=>" is the Picat version of the Prolog symbol ":-", I guess that it answers my question. – Samuel Magnano Mar 07 '22 at 16:37
  • 1
    This is in mostly true. More correct would be to say that Prolog's `:-` corresponds to Picat's non-deterministic (backtrackable) predicate operator `?=>`. Picat's `=>` defines a deterministic predicate. This is discussed a little more in Picat User Guide, section 1.2 "Defining Predicate". Also note that Picat now also supports the Prolog operator ":-" with the same meaning as in Prolog. – hakank Mar 07 '22 at 17:05

1 Answers1

2

Briefly, if you use => instead of :-, you are essentially writing a deterministic predicate. As we know that Prolog is a practical programming language and it is not necessary to keep all predicates pure. A lot of time, we actually write impure programs by cut and hope single sided unification. The => just provides a convenient mechanism to write such programs.

You can understand => by program transformation.

p(A1,A2,...An), C1, C2, ... => Body

is semantically equivalent to

p(V1,V2,...Vn) :-
    Pattern = p(A1,A2,...An),
    Args = p(V1,V2,...Vn),
    subsumes_term(Pattern, Args),
    Pattern = Args,
    C1, C2, ...,
    !,
    Body.

More detail see https://swi-prolog.discourse.group/t/picat-style-matching

chansey
  • 1,266
  • 9
  • 20