3 ms·
The right way to do this is the way Prolog does it. It doesn't matter if you say VAR = 12 or 12 = VAR or 1,2,10 = A, B, C It does whatever it takes to make the
by bfuclusion 6y ago
The right way to do this is the way Prolog does it.
It doesn't matter if you say VAR = 12
or 12 = VAR or 1,2,10 = A, B, C
It does whatever it takes to make the left and the right sides equivalent to each other.
- thrwn_frthr_awy 6y agoThat is interesting. How does it work when a variable is on each side? foo = 1 bar = 2 foo = bar
- nemetroid 6y agoIt will share with you its wisdom (the last line is printed by the interpreter): ?- FOO = 1, BAR = 2, FOO = BAR. false.
- JadeNB 6y agoAnd if you haven't bound them previously, it does exactly the right thing, and regards them as now the same variable. ?- FOO = BAR, FOO = 1, print(BAR). 1
- thrwn_frthr_awy 6y agoThat’s neat. Is there a separate syntax for var to var assignment or are variables immutable in Prolog?
- nemetroid 6y agoVariables are immutable, but note that it's the contradiction that leads to the "false" response, there's no issue with the assignment itself: ?- FOO = 1, BAR = 1, FOO = BAR. FOO = BAR, BAR = 1.
- bfuclusion 6y agoErlang is interesting too here, in that it basically works the same way (unification essentially via substitution). If you can't make it work, a program exception is thrown instead of a false language. This all makes sense since prolog talks more about logic, and erlang is GP language.