mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.08k stars 125 forks source link

Missing resisual display after copy_term/2 #2016

Closed infradig closed 1 year ago

infradig commented 1 year ago
$ scryer-prolog
?- freeze(A,A>50), copy_term(A,B).
   freeze:freeze(A,A>50).   % where is B?

?- freeze(A,A>50), copy_term(A,B), A=51.
   A = 51.  % expected, but what about B?

?- freeze(A,A>50), copy_term(A,B), A=51, B=1.
   false.   % expected, so B was there
?- 
triska commented 1 year ago

Related: #923.

A small modification of one of the examples posted there:

?- X in 0..3, copy_term(X, Y).
   clpz:(X in 0..3), unexpected, unsound.
triska commented 1 year ago

@infradig: There is also the question whether attributes indeed should be copied by copy_term/2. Scryer seems to follow SICStus in that attributes are not copied.

Copying the attributes "as they are" is typically not meaningful in any case.

So, I think it can be argued that the above is in fact to be expected?

Do you have a case where copy_term/2 actually should copy attributes? You can always use copy_term/3 instead, and call the residual goals (with maplist(call, Gs)) to constrain the copy!

infradig commented 1 year ago

Don't you mean Scryer & Sicstus do copy attributes? See the example above. Scryer just doesn't seem to display them.

On Thu, 14 Sept 2023, 07:58 Markus Triska, @.***> wrote:

@infradig https://github.com/infradig: There is also the question whether attributes indeed should be copied by copy_term/2. Scryer seems to follow SICStus in that attributes are not copied.

Copying the attributes "as they are" is typically not meaningful in any case.

So, I think it can be argued that the above is in fact to be expected?

Do you have a case where copy_term/2 actually should copy attributes? You can always use copy_term/3 instead, and call the residual goals (with maplist(call, Gs)) to constrain the copy!

— Reply to this email directly, view it on GitHub https://github.com/mthom/scryer-prolog/issues/2016#issuecomment-1718370171, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNKSEW2IAHV5SXS23UTNBDX2IT6VANCNFSM6AAAAAA4V3HCSU . You are receiving this because you were mentioned.Message ID: @.***>

infradig commented 1 year ago

Also Swi & Ciao copy attributes, B-Prolog doesn't. I don't have Sicstus since the licensing procedure is too bothersome.

?- freeze(A,(write(here),nl)), copy_term(A,B), A=1, B=2.
here
here
   A = 1, B = 2.
?- 
UWN commented 1 year ago

SICStus:

| ?- freeze(V,false), V=1.    
no
| ?- freeze(V,false).                  
prolog:freeze(V,user:false) ? 
yes
| ?- freeze(V,false), copy_term(V,VC).
prolog:freeze(V,user:false) ? ;
no
| ?- freeze(V,false), copy_term(V,VC), V = 1.
no
| ?- freeze(V,false), copy_term(V,VC), VC = 1.
VC = 1,
prolog:freeze(V,user:false) ? ;
no
infradig commented 1 year ago

Interesting. I presume findall/3 for Sictus doesn't copy either?

$ scryer-prolog
?- freeze(A,(write(A),nl)),L=[A],findall(X,member(X,L),L2),A=1, L2=[H1], H1=2.
1
2
   A = 1, L = [1], L2 = [2], H1 = 2.
?- 
$ bp
B-Prolog Version 8.1, All rights reserved, (C) Afany Software 1994-2014.
| ?- freeze(A,(write(A),nl)),L=[A],findall(X,member(X,L),L2),A=1, L2=[H1], H1=$
1 
A = 1
L = [1]
L2 = [2]
H1 = 2
yes
| ?- 
UWN commented 1 year ago

In the past, however, that is prior to version 4, SICStus did copy, and that since at least version 0.7 of 1990. So SICStus is the system with most experience in these areas. And after about 16 years of experience, version 4 came out that no longer copied but provided two new built-ins call_residue_vars/2 and copy_term/3 instead.

In many areas, this implicit copying lead to many bugs and to quite inefficient and often unstable mechanisms. Think of call_residue/2 which has been abandoned as well. YAP still has a SICStus compatible implementation. Look it up to see how complex it is.

That is the SICStus development, systems that came later somehow ignored the lessons learned.

infradig commented 1 year ago

Fine by me. Less complex the better.

On Thu, 14 Sept 2023, 15:09 UWN, @.***> wrote:

In the past, however, that is prior to version 4, SICStus did copy, and that since at least version 0.7 of 1990. So SICStus is the system with most experience in these areas. And after about 16 years of experience, version 4 came out that no longer copied but provided two new built-ins call_residue_vars/2 and copy_term/3 instead.

In many areas, this implicit copying lead to many bugs and to quite inefficient and often unstable mechanisms. Think of call_residue/2 which has been abandoned as well. YAP still has a SICStus compatible implementation. Look it up to see how complex it is.

That is the SICStus development, systems that came later somehow ignored the lessons learned.

— Reply to this email directly, view it on GitHub https://github.com/mthom/scryer-prolog/issues/2016#issuecomment-1718772612, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNKSEXOQ5F7TG3VPVPH2B3X2KGSFANCNFSM6AAAAAA4V3HCSU . You are receiving this because you were mentioned.Message ID: @.***>