trealla-prolog / trealla

A compact, efficient Prolog interpreter written in plain-old C.
MIT License
274 stars 13 forks source link

Imperfection of creating operators #596

Open flexoron opened 2 months ago

flexoron commented 2 months ago

v2.56.12


$ tpl
?- current_op(X,Y,&).
   false. % ok, free

?- op(1,fy,&).
   true.
?- op(1,yf,&).
   throw(error(permission_error(create,operator,&),op/3)). % unexpected, see below
?- halt.

$ tpl
?- current_op(X,Y,&).
   false. % again, free

?- op(1,yf,&).  % the other way around
   true.
?- op(1,fy,&).
   true.        % hopscop, no permission_error?

?- current_op(X,Y,&).
   X = 1, Y = fy. 
?- %%% Missing  X = 1, Y = yf. %%%
infradig commented 2 months ago

Logtalk iso_op_3_10 needs to be changed to add Trealla to the conditional test @pmoura

flexoron commented 2 months ago

ECLiPSe, Who else? SWI

$ eclipse
[eclipse 1]: op(1,fy,&).
[eclipse 2]: op(1,yf,&).
[eclipse 3]: op(1,xfx,&).
[eclipse 4]: [user].
&(x).
&(x,x).

[eclipse 5]: X&, &Y, X&Y.
X = x
Y = x
[eclipse 7]: X& .
X = x
$ tpl
?- op(1,fy,&).
   true.
?- op(1,yf,&).
   true.
?- op(1,xfx,&).
   true.
?- [user].
&(x).
&(x,x).

?- current_op(X,Y,&).
   X = 1, Y = fy
;  X = 1, Y = yf
;  X = 1, Y = xfx.

?-  X&, &Y, X&Y.
Error: syntax error, quotes needed around operator ',', user:1
?-  X& .
Error: syntax error, missing operand to infix, user:1

Also

$ tpl
?- op(1,yf,&).
   true.
?- [user].
&(x).
   true.
?- X& .
   X = x.
?- X& , true.
Error: syntax error, quotes needed around operator ',', user:1 % Meaning?
?-
infradig commented 2 months ago

Yes, the change to allow both postfix & infix needs a tad more work.

On Thu, Sep 19, 2024 at 11:30 AM flexoron @.***> wrote:

ECLiPSe, Who else?

$ eclipse

&(x). &(x,x).

[eclipse 5]: X&, &Y, X&Y. X = x Y = x [eclipse 7]: X& . X = x

$ tpl ?- op(1,fy,&). true. ?- op(1,yf,&). true. ?- op(1,xfx,&). true. ?- [user]. &(x). &(x,x).

?- current_op(X,Y,&). X = 1, Y = fy ; X = 1, Y = yf ; X = 1, Y = xfx.

?- X&, &Y, X&Y. Error: syntax error, quotes needed around operator ',', user:1 ?- X& . Error: syntax error, missing operand to infix, user:1

— Reply to this email directly, view it on GitHub https://github.com/trealla-prolog/trealla/issues/596#issuecomment-2359733758, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNKSEV6PZ6CYNJCUS6TECLZXISNBAVCNFSM6AAAAABOOXAXIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNJZG4ZTGNZVHA . You are receiving this because you commented.Message ID: @.***>

flexoron commented 1 month ago

v2.56.14 Partial Result. Only this works (a bit):

$ tpl
?- op(1,xfx,&).
   true.
?- op(1,fy,&). % this first
   true.
?- op(1,yf,&). % then this, otherwise non-functional
   true.
?- [user]. &(x). &(x,x). end_of_file.
   true.
?- X& .
   X = x.
?- (X&),true. % brackets additionally required
   X = x.
?- &X,(Y&),X&Y.
   X = x, Y = x.
?- (Y&),&X,X&Y.
   Y = x, X = x.
?- 
infradig commented 1 month ago

Hmm, you're right. But it's daft to have an operator be both prefix & postfix.

On Thu, Sep 19, 2024 at 6:37 PM flexoron @.***> wrote:

v2.56.14 Partial Result. Only this works (a bit):

$ tpl ?- op(1,xfx,&). true. ?- op(1,fy,&). % this first true. ?- op(1,yf,&). % then this, otherwise non-functional true. ?- [user]. &(x). &(x,x). end_of_file. true. ?- X& . X = x. ?- (X&),true. % brackets additionally required X = x. ?- &X,(Y&),X&Y. X = x, Y = x. ?- (Y&),&X,X&Y. Y = x, X = x. ?-

— Reply to this email directly, view it on GitHub https://github.com/trealla-prolog/trealla/issues/596#issuecomment-2360370914, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFNKSEWN3Y7W46CXY6WXRWLZXKELNAVCNFSM6AAAAABOOXAXIKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNRQGM3TAOJRGQ . You are receiving this because you commented.Message ID: @.***>

flexoron commented 1 month ago

But not too bad. At least eclipse,swipl approached. A question might be: listing. &x or x& or both

?- op(1,xfx,&).
   true.
?-  op(1,fy,&).
   true.
?- op(1,yf,&).
   true.
?- [user]. &(x). &(x,x). end_of_file.
   true.
?- listing.
&x.
x&x.
   true.
?- halt.

$ tpl
?- op(1,xfx,&).
   true.
?-  op(1,yf,&).
   true.
?-  op(1,fy,&).
   true.
?- [user]. &(x). &(x,x). end_of_file.
   true.
?- listing.
x&.
x&x.
   true.
?- 
flexoron commented 1 month ago

Left in tpl's 'issue' basket: Scryer and the others don't care about the order ...

$ scryer-prolog -f
?- op(1,yf,&).
   true.
?- op(1,fy,&).
   true.
?- [user].
&x.
x& .

?- &X.
   X = x
;  X = x.
?- X& .
   X = x
;  X = x.
?- 

%% ... and don't need brackets %%
?- X&,&X,true.
   X = x
;  X = x
;  X = x
;  X = x.
?- &X,X&,true.
   X = x
;  X = x
;  X = x
;  X = x.
?- 
infradig commented 1 month ago

I think you should define the prefix op before defining it as postfix, it's the natural order of things ;-)

flexoron commented 1 month ago
Ah this explains why C-Programmers are supranatural extraterrestrials. for(complex i=∞i;;i++)i--;-)

https://www.youtube.com/watch?v=tGXSYfFxUA4