Skip to content

Commit 1783d2d

Browse files
committed
enable/disable output repleats
1 parent f05169c commit 1783d2d

File tree

4 files changed

+66
-8
lines changed

4 files changed

+66
-8
lines changed

prolog/metta_lang/metta_debug.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@
859859
catch_oce(Goal),
860860
set_prolog_flag(occurs_check,Was)).
861861

862+
woc(TFE,Goal):- current_prolog_flag(occurs_check,TFE),!,call(Goal).
862863
woc(TFE,Goal):- current_prolog_flag(occurs_check,TFE),!,precopy_term(Goal,CGoal),!,call(CGoal),uncopy_term(Goal,CGoal).
863864
woc(TFE,Goal):- current_prolog_flag(occurs_check,Was),redo_call_cleanup(set_prolog_flag(occurs_check,TFE),Goal,set_prolog_flag(occurs_check,Was)).
864865

prolog/metta_lang/metta_eval.pl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@
203203
% Evaluates the given term X and succeeds if X is not a constraint (i.e. \+ iz_conz(X)) and is callable, and calling X succeeds.
204204
%
205205
% If X is not callable, this predicate will attempt to evaluate the arguments of X (using eval_args/2) and succeed if the result is not False.
206-
eval_true(X):- \+ iz_conz(X), callable(X),!, call(X).
206+
eval_true(X):- \+ iz_conz(X), callable(X), !, call(X).
207+
eval_true([F,X,Y]):- F=='=alpha',!,'=alpha'(X,Y).
207208
eval_true(X):- eval_args(X,Y), is_True(Y) , !.
208209

209210
eval(Depth,Self,X,Y):- eval('=',_,Depth,Self,X,Y).
@@ -1359,9 +1360,8 @@
13591360
equal_enough_for_test_l(P2,X,Y):- must_be(proper_list,X), must_be(proper_list,Y), sort(X,X0),sort(Y,Y0),
13601361
maplist(equal_enough_for_test(P2),X0,Y0).
13611362

1362-
1363+
equal_enough_for_test_renumbered(P2,X0,Y0):- X0=@=Y0, \+ is_negation_f2(P2), !. % ignore(with_debug(varnames,equal_enough_for_test_renumbered2(P2,X0,Y0))).
13631364
equal_enough_for_test_renumbered(P2,X0,Y0):- equal_enough_for_test_renumbered2(P2,X0,Y0),!.
1364-
equal_enough_for_test_renumbered(P2,X0,Y0):- X0=@=Y0, \+ is_negation_f2(P2), ignore(with_debug(varnames,equal_enough_for_test_renumbered2(P2,X0,Y0))).
13651365

13661366
equal_enough_for_test_renumbered2(P2,X0,Y0):- equal_renumbered(X0,Y0,XX,YY), equal_enough_for_test(P2, XX,YY).
13671367

@@ -3965,7 +3965,7 @@
39653965
findall(H->B0, ((woc(metta_eq_def(Eq,Self,H,B0)),HC=@=H)), BL),
39663966
BL\==[],!,
39673967
must_or_die((
3968-
member(H->B0,BL),nl,
3968+
member(H->B0,BL),%nl,
39693969
print_templates(Depth,HC,rule(H,B0,_Nth,_Types)),
39703970
eval_args(Eq,RetType,Depth,Self,B0,BO))).
39713971

prolog/metta_lang/metta_interp.pl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4474,9 +4474,12 @@
44744474
transform_about(Fact, Rule, Cond), Cond=='True',!,
44754475
fact_store(KB, Rule, Fact, Cond).
44764476
*/
4477-
metta_atom0(_Inherit,_KB, Atom) :- Atom=@=[_676238, :, _674118],!,fail.
4478-
metta_atom0(_Inherit,_KB, Atom) :- Atom=@=[=, [_502628, _502592, _502598], _502424],!,fail.
4479-
metta_atom0(_Inherit,_Space, Atom) :- Atom = [V1, [Colon, Thing, V2], V3], Colon==':', nonvar(Thing),maplist(var,[V1,V2,V3]),!,fail.
4477+
dont_bother(Atom):- Atom=@=[_, :, _].
4478+
dont_bother(Atom):- Atom=@=[=, [_, _, _], _].
4479+
dont_bother(Atom):- Atom=@=[=, [_, _], _]. % maybe
4480+
dont_bother(Atom):- Atom = [V1, [Colon, Thing, V2], V3], Colon==':', nonvar(Thing),maplist(var,[V1,V2,V3]).
4481+
4482+
metta_atom0(_Inherit,_KB, Atom) :- dont_bother(Atom),!,fail.
44804483

44814484
% metta_atom([Superpose,ListOf], Atom) :- Superpose == 'superpose', is_list(ListOf), !, member(KB, ListOf), get_metta_atom_from(KB, Atom).
44824485
metta_atom0(_Inherit,Space, Atom) :- typed_list(Space, _, L), !, member(Atom, L).

prolog/metta_lang/metta_testing.pl

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,9 @@
296296
% Generates the test name based on the current number.
297297
get_test_name(Number, TestName),
298298
% Prints the test name in an HTML heading format.
299-
format('~N~n;<h3 id="~w">;; ~w</h3>~n', [TestName, TestName]).
299+
format('~N~n;<h3 id="~w">;; ~w</h3>~n', [TestName, TestName]),
300+
flush_output.
301+
300302

301303
%! ensure_increments(:Goal) is det.
302304
%
@@ -387,6 +389,58 @@
387389
% Evaluates the main assertion goal.
388390
once(loonit_asserts1(Exec, Pro, G)).
389391

392+
393+
with_output_and_error_to(Out, Err, Goal) :-
394+
current_input(OrigIn),
395+
current_output(OrigOut),
396+
current_error(OrigErr),
397+
setup_call_cleanup(
398+
set_prolog_IO(OrigIn, Out, Err),
399+
Goal,
400+
set_prolog_IO(OrigIn, OrigOut, OrigErr)
401+
).
402+
403+
with_disabled_writing(Goal) :-
404+
setup_call_cleanup(disable_writing,Goal,enable_writing).
405+
406+
:- dynamic saved_io/3.
407+
408+
disable_writing :- saved_io(_, _, _),!.
409+
disable_writing :-
410+
\+ saved_io(_, _, _), % prevent double disable
411+
current_input(In),
412+
current_output(Out),
413+
stream_property(Err, alias(user_error)),
414+
assertz(saved_io(In, Out, Err)),
415+
disabled_stream(Null),
416+
set_prolog_IO(In, Null, Null),
417+
set_stream(Null, alias(disabled_output)).
418+
419+
enable_writing :-
420+
\+ saved_io(_, _, _), !.
421+
enable_writing :-
422+
retract(saved_io(In, Out, Err)),!,
423+
set_prolog_IO(In, Out, Err),
424+
current_output(WasOut),
425+
( catch(close(WasOut), _, true)
426+
-> true
427+
; true
428+
),
429+
set_prolog_IO(In, Out, Err).
430+
/*
431+
enable_writing:- original_user_error(Err),
432+
current_input(In),
433+
set_prolog_IO(In, Err, Err).
434+
*/
435+
436+
disabled_stream(Stream):-
437+
open_prolog_stream(oops, write, Stream, []).
438+
439+
oops:stream_write(_,S2):- S2=="\n", nb_current(lw,S1),S1==S2,!, enable_writing,trace,disable_writing. %,original_user_error(Err), writeq(Err,S2), write(Err,S2).
440+
oops:stream_write(_,S2):- nb_setval(lw,S2), !, original_user_error(Err), write(Err,S2).
441+
%oops(S):- trace,writeln(S).
442+
:- set_prolog_flag(gc,false).
443+
390444
%! give_pass_credit(+TestSrc, +Precondition, +Goal) is det.
391445
%
392446
% Marks a test as passed and updates the success counter if conditions are met.

0 commit comments

Comments
 (0)