Any programmer with some experience with Prolog knows the benefits of using unary notation for numbers. For example, if we represent a number as a list of 1 "(" 4 "is a list of" [1,1,1,1] ", etc.), we can define:
unary_succ(X,[1|X]).
The following requests are expected:
?- X=[1,1],unary_succ(X,Y). X = [1, 1], Y = [1, 1, 1]. ?- unary_succ(X,Y),X=[1,1]. X = [1, 1], Y = [1, 1, 1]. ?- unary_succ(X,Y),Y=[1,1]. X = [1], Y = [1, 1].
Thus, the unary_succ (X, Y) operator βbindsβ X and Y in such a way that if, after the fact is specified, one of these variables is bound to the value, the other does.
However, this behavior is not possible if we use the internal representation of a number:
?- X=2,succ(X,Y). X = 2, Y = 3. ?- succ(X,Y),X=2. ERROR: succ/2: Arguments are not sufficiently instantiated ?- succ(X,Y),Y=2. ERROR: succ/2: Arguments are not sufficiently instantiated
In my opinion, it will be very useful for previous statements and similar cases to do what was expected. That is, we need to bind the two variables in such a way that when one of them is tied to a value, the other fulfills the rule established earlier.
My questions:
a) some easy way to do this in Prolog.
b) if this is not possible, any other programming language that supports this function?
Any comments are welcome.
Thanks to everyone.
* Adding me *
Another example:
user_id(john,1234). user_id(tom,5678).
and requests:
X=john,user_id(X,Y). user_id(X,Y),X=john
which are currently being addressed through backtracking.