Skip to content

Commit

Permalink
Remove unneeded var(Module) -> ... clauses
Browse files Browse the repository at this point in the history
  • Loading branch information
adri326 committed Jan 1, 2025
1 parent 0c0f025 commit 911d536
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 36 deletions.
15 changes: 3 additions & 12 deletions src/lib/builtins.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@
% Asserts (inserts) a new clause (rule or fact) into the current module.
% The clause will be inserted at the beginning of the module.
asserta(Clause0) :-
loader:strip_subst_module(Clause0, user, Module, Clause),
loader:strip_module(Clause0, Module, Clause),
asserta_(Module, Clause).

asserta_(Module, (Head :- Body)) :-
Expand All @@ -1191,7 +1191,7 @@
% Asserts (inserts) a new clause (rule or fact) into the current module.
% The clase will be inserted at the end of the module.
assertz(Clause0) :-
loader:strip_subst_module(Clause0, user, Module, Clause),
loader:strip_module(Clause0, Module, Clause),
assertz_(Module, Clause).

assertz_(Module, (Head :- Body)) :-
Expand All @@ -1211,15 +1211,9 @@
loader:strip_module(Clause0, Module, Clause),
( Clause \= (_ :- _) ->
loader:strip_module(Clause, Module, Head),
( var(Module) -> Module = user
; true
),
Body = true,
retract_module_clause(Head, Body, Module)
; Clause = (Head :- Body) ->
( var(Module) -> Module = user
; true
),
retract_module_clause(Head, Body, Module)
).

Expand Down Expand Up @@ -1374,10 +1368,7 @@
'$get_db_refs'(_, _, _, PIs),
lists:member(Pred, PIs)
; loader:strip_module(Pred, Module, UnqualifiedPred),
( var(Module),
\+ functor(Pred, (:), 2)
; atom(Module)
),
atom(Module),
UnqualifiedPred = Name/Arity ->
( ( nonvar(Name), \+ atom(Name)
; nonvar(Arity), \+ integer(Arity)
Expand Down
30 changes: 6 additions & 24 deletions src/lib/dcgs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,6 @@
phrase(GRBody, S0) :-
phrase(GRBody, S0, []).

call_with_module(M:Body) :-
(
var(M) -> call(Body)
; atom(M), call(M:Body)
).

call_with_module(M:Body, X, Y) :-
(
var(M) -> call(Body, X, Y)
; atom(M), call(M:Body, X, Y)
).

call_with_module(M:Body, X, Y, Z) :-
(
var(M) -> call(Body, X, Y, Z)
; atom(M), call(M:Body, X, Y, Z)
).

%% phrase(+Body, ?Ls, ?Ls0).
%
% True iff Body describes part of the list Ls and the rest of Ls is Ls0.
Expand All @@ -100,8 +82,8 @@
; nonvar(GRBody1),
dcg_constr(GRBody1),
dcg_body(GRBody1, S0, S, GRBody2) ->
call_with_module(M:GRBody2)
; call_with_module(M:GRBody1, S0, S)
call(M:GRBody2)
; call(M:GRBody1, S0, S)
).

phrase(GRBody, Arg, S0, S) :-
Expand All @@ -114,8 +96,8 @@
GRBody2 =.. GRBodys2,
dcg_constr(GRBody2),
dcg_body(GRBody2, S0, S, GRBody3) ->
call_with_module(M:GRBody3)
; call_with_module(M:GRBody1, Arg, S0, S)
call(M:GRBody3)
; call(M:GRBody1, Arg, S0, S)
).

phrase(GRBody, Arg1, Arg2, S0, S) :-
Expand All @@ -128,8 +110,8 @@
GRBody2 =.. GRBodys2,
dcg_constr(GRBody2),
dcg_body(GRBody2, S0, S, GRBody3) ->
call_with_module(M:GRBody3)
; call_with_module(M:GRBody1, Arg1, Arg2, S0, S)
call(M:GRBody3)
; call(M:GRBody1, Arg1, Arg2, S0, S)
).

% The same version of the below two dcg_rule clauses, but with module scoping.
Expand Down

0 comments on commit 911d536

Please sign in to comment.