Skip to content

Commit

Permalink
towards #221 by adding a value --vn to command lines turns on the bug…
Browse files Browse the repository at this point in the history
…fix.. but this adds some slight dangers to be discussed later
  • Loading branch information
TeamSPoon committed Dec 13, 2024
1 parent 8b127d0 commit d92ae1f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
1 change: 1 addition & 0 deletions prolog/metta_lang/metta_interp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@
option_value_name_default_type_help('answer-format', 'show', ['rust', 'silent', 'detailed'], "Control how results are displayed", 'Output and Logging').
option_value_name_default_type_help('repeats', true, [true, false], "false to avoid repeated results", 'Miscellaneous').
option_value_name_default_type_help('time', true, [false, true], "Enable or disable timing for operations (in Rust compatibility mode, this is false)", 'Miscellaneous').
option_value_name_default_type_help('vn', auto, [auto, true, false], "Enable or disable, (auto = enable but not if it breaks stuff) EXPERIMENTAL BUG-FIX where variable names are preserved (see https://github.com/trueagi-io/metta-wam/issues/221)", 'Miscellaneous').

% Testing and Validation
option_value_name_default_type_help('synth-unit-tests', false, [false, true], "Synthesize unit tests", 'Testing and Validation').
Expand Down
15 changes: 14 additions & 1 deletion prolog/metta_lang/metta_loader.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3347,7 +3347,20 @@
% @arg NamedVarsList The list of named variables.
%
subst_vars(TermWDV, NewTerm, NamedVarsList) :-
subst_vars(TermWDV, NewTerm, [], NamedVarsList).
subst_vars(TermWDV, NewTerm, [], NamedVarsList),
if_t(fast_option_value('vn', 'true'), memorize_varnames(NamedVarsList)).


memorize_varnames(NamedVarsList):- \+ compound(NamedVarsList),!.
memorize_varnames([NamedVar|NamedVarsList]):- !,
memorize_varname(NamedVar),
memorize_varnames(NamedVarsList).
memorize_varnames(_).
memorize_varname(NamedVar):- \+ compound(NamedVar),!.
memorize_varname(Name=Var):- var(Var),atomic(Name),put_attr(Var,vn,Name).
memorize_varname(_).



%! subst_vars(+Term, -Term, +Acc, -NamedVarsList) is det.
%
Expand Down
4 changes: 2 additions & 2 deletions prolog/metta_lang/metta_printer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -554,13 +554,13 @@
%
write_dvar(S) :-
% If S is an underscore, output the name directly.
S == '_', !, write_dname(S).
S == '_', !, write('$_').
write_dvar(S) :-
% If S is a double underscore, write `$` to represent it.
S == '__', !, write('$').
write_dvar(S) :-
% For an unbound variable, get its name and write it.
var(S), get_var_name(S, N), write_dname(N), !.
var(S), get_var_name(S, N), write_dvar(N), !.
write_dvar(S) :-
% For an unbound variable without a name, format it as `$<variable>`.
var(S), !, format('$~p', [S]).
Expand Down
6 changes: 5 additions & 1 deletion prolog/metta_lang/metta_repl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,11 @@
%
write_bsrc(Var):- Var=='Empty',!,write(Var). % Special case: write 'Empty' directly.
write_bsrc(Var):- ground(Var),!,write_bsrc1(Var). % If the variable is ground, write it directly.
write_bsrc(Var):- copy_term(Var,Copy,Goals),Var=Copy,write_bsrc_goal(Var,Goals). % For non-ground terms, handle goals.
write_bsrc(Var):- copy_term(Var,Copy,Goals),Var=Copy,
exclude(excluded_hidden_goal,Goals,UnhiddenGoals),
write_bsrc_goal(Var,UnhiddenGoals). % For non-ground terms, handle goals.

excluded_hidden_goal(name_variable(_,_)).

%! write_bsrc_goal(+Var, +Goals) is det.
%
Expand Down

0 comments on commit d92ae1f

Please sign in to comment.