From 7adcbee75d8fad85e7d9df90ee24d4e1fdf62f8f Mon Sep 17 00:00:00 2001 From: logicmoo Date: Mon, 2 Dec 2024 01:30:35 -0800 Subject: [PATCH] :- dynamic(enabled_log_progress/0). --- src/canary/metta_debug.pl | 34 ++++++++++--------- src/canary/metta_interp.pl | 12 +++---- src/canary/metta_parser.pl | 2 ++ .../nqueens/format_args_ordered.metta.pl | 8 +++-- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/canary/metta_debug.pl b/src/canary/metta_debug.pl index 261001debec..5466c20c177 100755 --- a/src/canary/metta_debug.pl +++ b/src/canary/metta_debug.pl @@ -771,32 +771,31 @@ log_file_type(prolog). -into_blocktype(InfoType,Goal):- !, - enter_markdown(InfoType),!, - Goal. - %setup_call_cleanup(format('~N```~w~n',[InfoType]),Goal, format('~N```~n',[])). +into_blocktype(InfoType,Goal):- enter_markdown(InfoType),!,call(Goal). -into_blocktype(InfoType,Goal):- log_file_type(markdown), !, - setup_call_cleanup(format('~N```~w~n',[InfoType]),Goal, format('~N```~n',[])). -into_blocktype(InfoType,Goal):- log_file_type(prolog), !, - setup_call_cleanup(format('~N```~w~n',[InfoType]),Goal, format('~N```~n',[])). - -into_blocktype(InfoType,Goal):- log_file_type(prolog), !, - setup_call_cleanup(format('~N/*~n```~w~n*/~n',[InfoType]),Goal, format('~N/*~n```~n*/~n',[])). +%into_blocktype(InfoType,Goal):- log_file_type(markdown), !, setup_call_cleanup(format('~N```~w~n',[InfoType]),Goal, format('~N```~n',[])). +%into_blocktype(InfoType,Goal):- log_file_type(prolog), !, setup_call_cleanup(format('~N```~w~n',[InfoType]),Goal, format('~N```~n',[])). +%into_blocktype(InfoType,Goal):- log_file_type(prolog), !, setup_call_cleanup(format('~N/*~n```~w~n*/~n',[InfoType]),Goal, format('~N/*~n```~n*/~n',[])). output_language( InfoType, Goal ) :- log_file_type(Lang), !, % (Lang==prolog; Lang==metta),!, ((InfoType == Lang -> (must_det_ll((enter_markdown(Lang),leave_comment)),call(Goal)) ; (must_det_ll(enter_comment),into_blocktype(InfoType,Goal)))). -output_language( InfoType, Goal ) :- log_file_type(markdown), !, into_blocktype(InfoType,Goal). -output_language( comment, Goal ) :- log_file_type(markdown), !, call(Goal). -output_language( comment, Goal ) :- log_file_type(prolog), !, format('~N:- q.~n', [output_language( comment, Goal)]). -output_language( comment, Goal ) :- log_file_type(metta), !, in_cmt(Goal). +%output_language( InfoType, Goal ) :- log_file_type(markdown), !, into_blocktype(InfoType,Goal). +%output_language( comment, Goal ) :- log_file_type(markdown), !, call(Goal). +%output_language( comment, Goal ) :- log_file_type(prolog), !, format('~N:- q.~n', [output_language( comment, Goal)]). +%output_language( comment, Goal ) :- log_file_type(metta), !, in_cmt(Goal). + +:- dynamic(enabled_save_markdown/0). + :- dynamic(inside_comment/0). +leave_comment:- \+ enabled_save_markdown, !. leave_comment:- inside_comment,!, format('~N*/~n~n'),retract(inside_comment). leave_comment. + +enter_comment:- \+ enabled_save_markdown, !. enter_comment:- inside_comment,!. enter_comment:- format('~N~n/*~n'),assert(inside_comment). :- enter_comment. @@ -806,10 +805,13 @@ :- dynamic(inside_markdown/1). +leave_markdown(_):- \+ enabled_save_markdown, !. leave_markdown(_):- \+ inside_markdown(_),!. leave_markdown(Lang):- inside_markdown(Lang),!, format('~N```~n'),retract(inside_markdown(Lang)). -leave_markdown(_):- !. % inside_markdown(Other),!,leave_markdown(Other). +%leave_markdown(_):- inside_markdown(Other),!,leave_markdown(Other). leave_markdown(_Lang):- !. %format('~N```~n'),!. + +enter_markdown(_):- \+ enabled_save_markdown, !. enter_markdown(Lang):- inside_markdown(Lang),!. enter_markdown(Lang):- inside_markdown(Other),!,leave_markdown(Other),!,enter_markdown(Lang). enter_markdown(Lang):- log_file_type(Us),Us=Lang,inside_comment,!,format('~N```~w~n',[Lang]),asserta(inside_markdown(Lang)),leave_comment. diff --git a/src/canary/metta_interp.pl b/src/canary/metta_interp.pl index c026977df81..8e8710ef777 100755 --- a/src/canary/metta_interp.pl +++ b/src/canary/metta_interp.pl @@ -1787,9 +1787,9 @@ give_up(Why),pp_m(red,gave_up(Why)))). %format("########################X2 ~w ~w ~w\n",[Self,TermV,FOut]). - -o_s(['assertEqual'|O],S):- nonvar(O), o_s(O,S). -o_s(['assertEqualToResult'|O],S):- nonvar(O), o_s(O,S). +a_e('assertEqual'). a_e('assertNotEqual'). +a_e('assertEqualToResult'). a_e('assertNotEqualToResult'). +o_s([AE|O],S):- nonvar(AE), a_e(AE), nonvar(O), o_s(O,S). o_s([O|_],S):- nonvar(O), !, o_s(O,S). o_s(S,S). into_simple_op(Load,[Op|O],op(Load,Op,S)):- o_s(O,S),!. @@ -1853,7 +1853,7 @@ do_metta(true,exec,Self,Form,_Out). eval_H(Term,X):- catch_metta_return(eval_args(Term,X),X). -eval_H(StackMax,Self,Term,X):- fast_option_value(compile, save),!. +eval_H(_StackMax,_Self, Term,Term):- fast_option_value(compile, save),!. eval_H(StackMax,Self,Term,X):- catch_metta_return(eval_args('=',_,StackMax,Self,Term,X),X). /* eval_H(StackMax,Self,Term,X). @@ -2241,7 +2241,7 @@ %:- ensure_loaded(metta_help). :- enter_comment. - +:- current_prolog_flag(stack_limit,X),X_16 is X * 16, set_prolog_flag(stack_limit,X_16). :- initialization(use_corelib_file). :- initialization(use_metta_ontology). @@ -2268,7 +2268,7 @@ % Flush any pending output to ensure smooth runtime interactions flush_metta_output :- - with_output_to(user_error, (write_answer_output, ttyflush)). + write_answer_output, ttyflush. % Write out answers in hyperon-experimental format to user_error metta_runtime_write_answers(List) :- diff --git a/src/canary/metta_parser.pl b/src/canary/metta_parser.pl index 002c7b656b6..b72898227fc 100644 --- a/src/canary/metta_parser.pl +++ b/src/canary/metta_parser.pl @@ -357,6 +357,8 @@ % % @arg Fmt The format string used by ansi_format/3. % @arg Args The arguments to be used in the format string. +:- dynamic(enabled_log_progress/0). +log_progress(_Fmt, _Args):- \+ enabled_log_progress, !. log_progress(Fmt, Args):- ttyflush, io_to_err(ansi_format([bold, hfg(black)], Fmt, Args)), diff --git a/tests/performance/compare_algo/nqueens/format_args_ordered.metta.pl b/tests/performance/compare_algo/nqueens/format_args_ordered.metta.pl index 1608d72673e..2fa383999ab 100644 --- a/tests/performance/compare_algo/nqueens/format_args_ordered.metta.pl +++ b/tests/performance/compare_algo/nqueens/format_args_ordered.metta.pl @@ -441,9 +441,11 @@ ```prolog */ - :- do_metta_runtime(A, mc__nqueens(12, A)). - :- do_metta_runtime(A, mc__nqueens(13, A)). - :- do_metta_runtime(A, mc__nqueens(14, A)). +%:- do_metta_runtime(A, mc__nqueens(12, A)). +%:- do_metta_runtime(A, mc__nqueens(13, A)). +%:- do_metta_runtime(A, mc__nqueens(14, A)). 500 secs +:- do_metta_runtime(A, mc__nqueens(15, A)). +%:- do_metta_runtime(A, mc__nqueens(16, A)). /*