Skip to content

Commit

Permalink
better proimpting
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Dec 14, 2024
1 parent 56644ec commit f353c29
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 25 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,34 @@ metta+>^D # Exit the REPL with `ctrl-D`.

To run a script:
```bash
mettalog tests/baseline_compat/metta-morph_tests/nalifier.metta
mettalog exmaples/puzzles/nalifier.metta
```

To run a script and then enter the repl:
```bash
mettalog tests/baseline_compat/metta-morph_tests/nalifier.metta --repl
mettalog exmaples/puzzles//nalifier.metta --repl
metta+>!(query &self (because blue house keeps parrots the $who is the fish owner))
[(Succeed ((quote (because blue house keeps parrots the brit is the fish owner))))]
metta+>

```

Execute a unit test:
## Unit tests

One exmaple is provided in this repository
```bash
mettalog --test exmaples/tests/unit_test_example.metta
# The output is saved as an HTML file in the same directory.
```

The rest are in a large REPO @
```bash
git clone https://github.com/logicmoo/metta-testsuite/
ln -s metta-testsuite/tests/ ./tests
```

Run a single test
```bash
mettalog --test tests/baseline_compat/metta-morph_tests/tests0.metta
```
Execute baseline sanity tests:
Expand Down
14 changes: 11 additions & 3 deletions prolog/metta_lang/metta_interp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@

%metta_atom(KB,Atom):- KB == '&corelib', !, metta_atom_asserted('&self',Atom).
metta_atom(KB,Atom):- KB \== '&corelib', using_all_spaces,!, metta_atom('&corelib',Atom).
metta_atom(KB,Atom):- KB \== '&corelib', !, metta_atom('&corelib',Atom).
%metta_atom(KB,Atom):- KB \== '&corelib', !, metta_atom('&corelib',Atom).
metta_atom(KB,Atom):- KB \== '&corelib', !,
\+ \+ (metta_atom_asserted(KB,'&corelib'),
should_inherit_from_corelib(Atom)), !,
Expand Down Expand Up @@ -1633,16 +1633,24 @@

never_compile(X):- always_exec(X).

always_exec(exec(W)):- !, is_list(W), always_exec(W).
always_exec(W):- var(W),!,fail.
always_exec([H|_]):- always_exec_symbol(H),!.
always_exec(Comp):- compound(Comp),compound_name_arity(Comp,Name,N),symbol_concat('eval',_,Name),Nm1 is N-1, arg(Nm1,Comp,TA),!,always_exec(TA).
always_exec([H|_]):- always_exec_symbol(H),!.
always_exec(List):- \+ is_list(List),!,fail.
always_exec([Var|_]):- \+ symbol(Var),!,fail.
always_exec(['extend-py!'|_]):- !, fail.
always_exec([H|_]):- symbol_concat(_,'!',H),!. %pragma!/print!/transfer!/include! etc
always_exec(['assertEqualToResult'|_]):-!,fail.
always_exec(['assertEqual'|_]):-!,fail.
always_exec(_):-!,fail. % everything else

always_exec_symbol(Sym):- \+ symbol(Sym),!,fail.
always_exec_symbol(H):- symbol_concat(_,'!',H),!. %pragma!/print!/transfer!/bind!/include! etc
always_exec_symbol(H):- symbol_concat('add-atom',_,H),!.
always_exec_symbol(H):- symbol_concat('remove-atom',_,H),!.
always_exec_symbol(H):- symbol_concat('subst-',_,H),!.


file_hides_results([W|_]):- W== 'pragma!'.

if_t(A,B,C):- trace,if_t((A,B),C).
Expand Down
49 changes: 30 additions & 19 deletions prolog/metta_lang/metta_repl.pl
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,25 @@
% metta>
%
repl3 :-
% Create the prompt by writing it to an atom `P`.
with_output_to(atom(P), write_metta_prompt),
% Set up cleanup for the terminal prompt and execute repl4.
%% TODO: Set to ' ' (not '')
notrace(prompt(Was, P)),
notrace(prompt(Was, Was)),
setup_call_cleanup(
% Set the terminal prompt without tracing.
true,
set_metta_prompt,
% Flush the terminal and call repl4 to handle input.
((ttyflush, repl4, ttyflush)),
% After execution, restore the previous terminal prompt.
notrace(prompt(_, Was))).


% Create the prompt by writing it to an atom `P`.
set_metta_prompt:-
with_output_to(atom(P), write_metta_prompt),
prompt1(P),
prompt(_, P).



%! repl4 is det.
% Executes the REPL logic by reading the input, processing expressions, and handling directives or commands.
% The loop is managed through exceptions (e.g., restarting or ending input).
Expand Down Expand Up @@ -636,6 +642,7 @@

% Read the next line of input, accumulate it, and continue processing.
repl_read_next(Accumulated, Expr) :-
if_t(flag(need_prompt,1,0),(nl,set_metta_prompt)),
% Read a line from the current input stream.
read_line_to_string(current_input, Line),
% switch prompts after the first line is read
Expand Down Expand Up @@ -1132,10 +1139,13 @@
eval_args(Self, Term, X).

% Reset evaluation counter
interactively_do_metta_exec01(From,Self,_TermV,Term,X,NamedVarsList,Was,VOutput,FOut):-
interactively_do_metta_exec01(From,Self,TermV,Term,X,NamedVarsList,Was,VOutput,FOut):-
%format("%%%%%%%%%%%%%%%%%%%%%%%%%2 ~w\n",[Term]),
notrace((

% Reset result number flag
flag(result_num,_,0),

% Reset evaluation counters for a fresh start
reset_eval_num,

Expand All @@ -1161,26 +1171,26 @@

% Commented code for interactive control, previously enabled for file skipping
/* previously: if From = file(_Filename), option_value('exec',skip), \+ always_exec(BaseEval) */
(((From = file(_Filename), option_value('exec',skip), \+ always_exec(BaseEval)))
(((From = file(_Filename), option_value('exec',skip), \+ notrace(always_exec(BaseEval);always_exec(TermV))))
-> (
% Skip execution if conditions are met
GgGgGgGgGgG = (skip(Term),deterministic(Complete)),
% Mark as skipped
Skipping = 1,!,
% Previously: Output = "Skipped"
/* previously: color_g_mesg('#da70d6', (write('% SKIPPING: '), writeq(eval_H(500,Self,BaseEval,X)),writeln('.'))) */
color_g_mesg('#da70d6', (write('; SKIPPING: '), write_src_woi(TermV))),
prolog_only(if_t((TermV\=@=BaseEval),color_g_mesg('#da70d6', (write('\n% Thus: '), writeq(eval_H(500,Self,BaseEval,X)),writeln('.'))))),
true
)
; % Otherwise, execute the goal interactively
GgGgGgGgGgG = (
( if_t((From = file(_), option_value('exec',skip)),
color_g_mesg('#da7036', (write('\n; Always-Exec: '), write_src_woi(TermV)))),
GgGgGgGgGgG = (
% Execute Term and capture the result
(( (Term),deterministic(Complete),
% Transform output for display and store it in the result
xform_out(VOutput,Output), nb_setarg(1,Result,Output)))),
xform_out(VOutput,Output), nb_setarg(1,Result,Output))))),
!, % Ensure the top-level metta evaluation is completed

% Reset result number flag
flag(result_num,_,0),

% Prepare evaluation for the base term
PL=eval(Self,BaseEval,X),
Expand All @@ -1190,7 +1200,7 @@
\+ \+ (user:maplist(name_vars,NamedVarsList),
user:name_vars('OUT'=X),
/* previously: add_history_src(exec(BaseEval)) */
if_t(Skipping==1,writeln(' ; SKIPPING')),
%if_t(Skipping==1,writeln(' ; SKIPPING')),
/* previously: if_t(TermV\=BaseEval,color_g_mesg('#fa90f6', (write('; '), with_indents(false,write_src(exec(BaseEval)))))) */

% Handle interactive result output or non-interactive result history
Expand Down Expand Up @@ -1233,8 +1243,8 @@
(
(((ResNum==1,Complete==true)->(old_not_compatio(format('~N~nDeterministic: ', [])), !); %or Nondet
/* previously: handle deterministic result output */
(Complete==true -> (old_not_compatio(format('~N~nLast Result(~w): ',[ResNum])),! );
old_not_compatio(format('~N~nNDet Result(~w): ',[ResNum]))))),
(Complete==true -> (old_not_compatio(format('~N~nResult(~w): ',[ResNum])),! );
old_not_compatio(format('~N~nN(~w):',[ResNum]))))),
ignore(((
if_t( \+ symbolic(Output), not_compatio(nop(nl))),
%if_t(ResNum==1,in_answer_io(format('~N['))),
Expand All @@ -1247,7 +1257,7 @@
true)))) )) ))))),
in_answer_io(write_asrc((Output))),

not_compatio(extra_answer_padding(format('~N'))), % Just in case, add some virt space between answers
% not_compatio(extra_answer_padding(format('~N'))), % Just in case, add some virt space between answers

((Complete \== true, WasInteractive, DoLeap \== leap,
LeashResults > ResNum, ResNum < Max) -> Stepping = true ; Stepping = false),
Expand All @@ -1263,7 +1273,7 @@
maplist(print_var,NamedVarsListR), nop(nl)))) ; true))))),
(
(Stepping==true) ->
(old_not_compatio(write("~npress ';' for more solutions ")),get_single_char_key(C),
(old_not_compatio(format("~npress ';' for more solutions ")),get_single_char_key(C),
old_not_compatio((writeq(key=C),nl)),
(C=='b' -> (once(repl),fail) ;
(C=='m' -> make ;
Expand All @@ -1281,7 +1291,8 @@
*-> (ignore(Result = res(FOut)),ignore(Output = (FOut)))
; (flag(result_num,ResNum,ResNum),(ResNum==0->
(in_answer_io(nop(write('['))),old_not_compatio(format('~N<no-results>~n~n')),!,true);true))),
in_answer_io(write(']\n')),
in_answer_io((write(']'),if_t(\+ is_mettalog,nl))),
flag(need_prompt,_,1),
ignore(Result = res(FOut)).

old_not_compatio(G):- call(G),ttyflush.
Expand Down

0 comments on commit f353c29

Please sign in to comment.