]> Repositorios git - scryer-prolog.git/commitdiff
constrain bracketing to operators with pertaining arity
authorMarkus Triska <[email protected]>
Fri, 30 Jun 2023 16:01:17 +0000 (18:01 +0200)
committerMarkus Triska <[email protected]>
Fri, 30 Jun 2023 16:01:17 +0000 (18:01 +0200)
Example:

    ?- X = -->(a,b,c).
       X = -->(a,b,c).

src/toplevel.pl

index ff4638335f252028e906e757dc82d8b782c83bfe..d61e324ff4af44b3aea8b9b94d078287c89418a0 100644 (file)
@@ -208,8 +208,9 @@ needs_bracketing(Value, Op) :-
     nonvar(Value),
     \+ integer(Value),
     functor(Value, F, Arity),
-    current_op(FPrec, _, F),
+    current_op(FPrec, FSpec, F),
     current_op(EqPrec, EqSpec, Op),
+    arity_specifier(Arity, FSpec),
     (  Arity =:= 0 ->
        true
     ;  EqPrec < FPrec ->
@@ -222,6 +223,10 @@ needs_bracketing(Value, Op) :-
        memberchk(EqSpec, [fx,xfx,yfx])
     ).
 
+arity_specifier(0, _).
+arity_specifier(1, S) :- atom_chars(S, [_,_]).
+arity_specifier(2, S) :- atom_chars(S, [_,_,_]).
+
 write_goal(G, VarList, MaxDepth) :-
     (  G = (Var = Value) ->
        (  var(Value) ->