The concept doesn't really exist in Prolog. Once a variable is bound to a value, it literally ceases to be a variable. It becomes that to which it was bound.
Up vote 0 down vote favorite share g+ share fb share tw.
Thanks in advance prolog link|improve this question asked Mar 9 at 17:25Evrim A1.
This is not Prolog, please explain something more... – chac Mar 9 at 17:33 If this question isn't about unification and your intention is to treat A/3 like a predicate, then please see my post... – sharky Mar 10 at 3:36.
The concept doesn't really exist in Prolog. Once a variable is bound to a value, it literally ceases to be a variable. It becomes that to which it was bound.
That's why it's called unification. To do what you want to do, you need to do something like: swap( a( C , Y , V ) , a( Y , C , V ) ). You might want to pick up some reference material: Programming In Prolog.
William Clocksin and Christopher Mellish. Arguably the best introductory text for Prolog. The Art of Prolog.
Leon Sterling and Ehud Shapiro. Personally, I found this more useful than Clocksin and Mellish. These books look interesting, though I've not personal experience with them: The Craft of Prolog.
Richard O'Keefe. Clause and Effect: Prolog Programming for the Working Programmer. William Clocksin.
Many thanks for the post. But is it possible to do it without functions? I am looking for a simple substitution.
– Evrim A Mar 9 at 19:01 Prolog doesn't have functions. Or substitution. Once something is unified, it is a constant value, unless you backtrack through the unification and undo it.
You really need to read up on Prolog. If you don't want the book, there's a bunch of prolog tutorials out there. You need to learn to think in the prolog way.
It is a manifestly different thing than any of the common, Algol-derived procedural languages — C, C++, Cobol, Ada, whatever. If you don't want the book, there's a bunch of free tutorials out there on the 'web. – Nicholas Carey Mar 9 at 19:30 I guess "reference material" would be SWI Prolog, GNU Prolog, etc.. documentation.
The above are just "text books" with their own scope, most of them product neutral, which is good. There is also an ISO standard BTW. – Cookie Monster Mar 9 at 19:42 +1 for recommending these texts, they're classics :) – sharky Mar 9 at 3:17.
Just a thought: if you're treating A as a Prolog predicate (I'd assumed you would be if you're asking how this can be done in Prolog), it's certainly possible to express the following: 'A'(C, Y, V) :- 'A'(Y, C, V). That's actual Prolog syntax, by the way. It defines a predicate 'A'/3 which reverses the order of it's first two arguments.
In practice, however, such a predicate won't get your Prolog program very far, as it will force the interpretation of 'A'/3 into an infinite loop. However, if you simply wanted your database to contain 'A'/3 terms which reflect the intention that every fact inserted matching 'A'(Y, C, V) is also associated with another fact matching 'A'(C, Y, V) (for whatever reason), then it is indeed possible, as follows: 'A'(c, y, v). 'A'(C, Y, V) :- 'A'(Y, C, V).
Executing this gives:? - 'A'(X,Y,Z). X = c, Y = y, Z = v ; X = y, Y = c, Z = v ...note that this will continue on backtracking to give you alternate bindings, ad infinitum, which isn't very useful.
However, if your program just needed to test for the existence of particular 'A'/3 facts with this program, you could still use either once('A'(X,Y,Z)) (if your Prolog has the built-in once/1), or the compound subgoal 'A'(X,Y,Z),! Which would suffice, as long as one or more facts for 'A'/3 are asserted before the recursive definition. I wouldn't recommend actually doing any of this in a real Prolog program, though ;-).
In (non-backtracking) Prolog you work as in pure functional paradigm: your states aren't implicit in your variables' values, but rather are explicit in your variables' names. That means you don't have implicit change in state, but rather an explicit progression of states. I.e.
, swap(Y2,C2,Y,C) :- C2,Y2 = Y,C. You call it like swap(Y2,C2, Y,C). And use Y2,C2 wherever you used Y,C before.
That it, you have both versions, the prior and the current, but only use the latter one from now on. I know you said "no lists" but that's just a syntactic detail here, to ease on the eyes/fingers (you could also use round parentheses there). Alternatively, you could just write directly in your code C2,Y2 = Y,C, .... for the same effect (you don't need a third var to swap a value through it like you would in imperative setting).
Also, I heartily recommend the exceptionally lucid and clear book by Ivan Bratko, as well as The Art of Prolog. "Craft" is very diverse and "Clause" focuses on few examples, both perhaps better as secondary reading. Prolog Programming for Artificial Intelligence.
Ivan Bratko.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.