SWI-Prolog / pengines

Pengine and Prolog scratchpad
BSD 2-Clause "Simplified" License
57 stars 16 forks source link

Strange behaviour when solving goals with two answer vars #4

Closed torbjornlager closed 10 years ago

torbjornlager commented 10 years ago

?- jealous(X, Y). X = Y = vincent ; X = vincent, Y = marcellus ; X = marcellus, Y = vincent ; X = Y = marcellus ; X = Y = pumpkin ; X = Y = honey_bunny.

JanWielemaker commented 10 years ago

What is strange? This is exactly what the Prolog toplevel does as well.

torbjornlager commented 10 years ago

Oh, I guess I thought the idea was that the output could be read in by Prolog again? But never mind if this is not the case.

On Fri, May 30, 2014 at 12:24 PM, Jan Wielemaker notifications@github.com wrote:

What is strange? This is exactly what the Prolog toplevel does as well.

— Reply to this email directly or view it on GitHub https://github.com/SWI-Prolog/pengines/issues/4#issuecomment-44636607.

Torbjörn Lager Professor of General and Computational Linguistics Department of Philosophy, Linguistics and Theory of Science University of Gothenburg Box 200, SE-405 30 Gothenburg, Sweden Phone: +46317864962

JanWielemaker commented 10 years ago

I see you are right, the toplevel does

1 ?- X = Y, X=5.
X = Y, Y = 5.

You can fix this in swish.js, renderAnswer (if I recall correctly).

torbjornlager commented 10 years ago

Hmm, I looked at it, but I'm not sure I understand it all.

For example, I see:

if ( (residuals = answer.residuals) ) {

Note the assigment in the condition. Is that intentional or a typo?

Cheers, Torbjörn

On Fri, May 30, 2014 at 12:28 PM, Jan Wielemaker notifications@github.com wrote:

I see you are right, the toplevel does

1 ?- X = Y, X=5. X = Y, Y = 5.

You can fix this in swish.js, renderAnswer (if I recall correctly).

— Reply to this email directly or view it on GitHub https://github.com/SWI-Prolog/pengines/issues/4#issuecomment-44636896.

Torbjörn Lager Professor of General and Computational Linguistics Department of Philosophy, Linguistics and Theory of Science University of Gothenburg Box 200, SE-405 30 Gothenburg, Sweden Phone: +46317864962

JanWielemaker commented 10 years ago

That is ok. A = B binds A to B and is logically the same as B. Fixed the shared variable answer. So, each an answer consists of an array of bindings, each of which has an array of variables with the same value, the value and an array of substitutions to break cycles. In addition, an answer may have an array of residual goals, basically constraints on the variables.

Updated pengines.swi-prolog.org.