scryer-prolog icon indicating copy to clipboard operation
scryer-prolog copied to clipboard

Problem with clause

Open infradig opened this issue 4 years ago • 6 comments

This is taken from Logtalk...

:- initialization(main).

:- dynamic(legs/2).
legs(A, 7) :- A, call(A).

main :-
	clause(legs(C,7), Body),
	Body == (call(C),call(C)),
	write(succeeded), nl,
	halt.

main :-
	write(failed), nl,
	halt.

This should succeed, obviously, as do swipl & gprolog.

infradig avatar Dec 09 '20 07:12 infradig

Currently,

?- clause(legs(C,7), Body).
   Body = (C,call(C)). % unexpected

That is, there is no term-to-body conversion (7.6.2) which also interferes with the way how cut is handled.

UWN avatar Dec 09 '20 16:12 UWN

See also

call(',', C=!, (X=1,C;X=2)).

$ ~/.cargo/bin/scryer-prolog ?- call(',', C=!, (X=1,C;X=2)). C = !, X = 1. ?-

which should generate two solutions as the call to naked variable C is equivalent to call(C) and so the cut should be localized within that call.

$ gprolog | ?- call(',', C=!, (X=1,C;X=2)). C = ! X = 1 ? ; C = ! X = 2 (1 ms) yes | ?-

Note: the outer call is just fluff here and comes from a Logtalk example.

infradig avatar Feb 28 '21 23:02 infradig

Note: the outer call is just fluff here and comes from a Logtalk example.

The original test is indeed a test for the call/N predicate.

pmoura avatar Feb 28 '21 23:02 pmoura

This now fails because of the meta-predicate expansions:

?- clause(legs(C,7),Body), Body==(call(user:C),call(user:C)).
   Body = (call(user:C),call(user:C)).
?- clause(legs(C,7),Body), Body==(call(C),call(C)).
false.

I can't speak for GNU Prolog but I believe SWI uses an atom-based module system, not a predicate-based one.

mthom avatar Mar 09 '22 19:03 mthom

I can't speak for GNU Prolog but I believe SWI uses an atom-based module system, not a predicate-based one.

GNU Prolog doesn't provide a module system. SWI-Prolog module system is (like almost all systems) predicate-based. XSB is an example of an atom-based system.

pmoura avatar Mar 09 '22 19:03 pmoura

XSB is functor based. SWI is predicate based but not exactly like SICStus. It still can transmit module information in a module transparent manner. Also it does a lot of implicit :-dereferencing.

UWN avatar Mar 09 '22 20:03 UWN

With 40d3345cd538b826bc91f3592562c4a32f69415e:

$ scryer-prolog
?- [user].
:- initialization(main).

:- dynamic(legs/2).
legs(A, 7) :- A, call(A).

main :-
	clause(legs(C,7), Body),
	Body == (call(C),call(C)),
	write(succeeded), nl,
	halt.

main :-
	write(failed), nl,
	halt.

succeeded

pmoura avatar Sep 28 '23 10:09 pmoura