|
> Because Picat is a research language it's a little weird with putting expressions inside structures. If we did $state(1 + 1) it would store it as literally $state(1 + 1), not state(2). > Also you have to use dollar signs for definitions but no dollar signs for pattern matching inside a function definition. I have no idea why. I've heard of Picat before but haven't played with it. But from contrasting to Prolog I think I can guess what's going on. In Prolog, everything is an uninterpreted term. If you want arithmetic "expressions" to be "evaluated", you must explicitly ask for that with the is/2 predicate. Also, there are no "functions" to be "applied". So in Prolog you would write: action(state(A, Clipboard), To, Action, Cost) :-
NewA is A + Clipboard, % I want the number 2, not the term 1 + 1
To = state(NewA, Clipboard), % I want a data structure called state, not to apply a hypothetical "state" function
Action = ("P", To),
Cost = 1.
Picat turns these things around. There are expressions, there are functions, and the = operator does evaluate its right-hand side. So now if you write state(NewA, Clipboard) on the RHS of an = operator, the default would be to interpret this as a function call to the "state" function. There is no such function, and if there were, you wouldn't want to call it here. You want a structure called "state". So you mark it as a structure construction rather than a function call.This has nothing to do with being "a research language", just having to do with having to be explicit about interpreting things as data vs. code. It's the same as quote in Lisp: sometimes you want (f a b) to be a function application, and sometimes you want to build a list containing f, a, and b. In Picat as in Lisp, you need to use a quoting mechanism in the latter case. |