Skip to content

Commit

Permalink
once_writeq_nl
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Aug 30, 2024
1 parent 73a2c49 commit 8949194
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/canary/metta_interp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@
:-dynamic(user:loaded_into_kb/2).
:- dynamic(user:is_metta_dir/1).

once_writeq_ln(_):- \+ clause(pfcTraceExecution,true),!.
once_writeq_ln(P):- nb_current('$once_writeq_ln',W),W=@=P,!.
once_writeq_ln(P):-
once_writeq_nl(_):- \+ clause(pfcTraceExecution,true),!.
once_writeq_nl(P):- nb_current('$once_writeq_ln',W),W=@=P,!.
once_writeq_nl(P):-
\+ \+ (numbervars(P,444,_,[attvar(skip),singletons(true)]),
ansi_format([fg(cyan)],'~N~q.~n',[P])),nb_setval('$once_writeq_ln',P),!.
% TODO uncomment this next line but it is breaking the curried chainer
% pfcAdd_Now(P):- pfcAdd(P),!.
pfcAdd_Now(P):- current_predicate(pfcAdd/1),!, once_writeq_ln(pfcAdd(P)),pfcAdd(P).
pfcAdd_Now(P):- once_writeq_ln(asssert(P)),assert(P).
pfcAdd_Now(P):- current_predicate(pfcAdd/1),!, once_writeq_nl(pfcAdd(P)),pfcAdd(P).
pfcAdd_Now(P):- once_writeq_nl(asssert(P)),assert(P).
%:- endif.

system:copy_term_g(I,O):- ground(I),!,I=O.
Expand Down
2 changes: 0 additions & 2 deletions src/canary/metta_loader.pl
Original file line number Diff line number Diff line change
Expand Up @@ -461,8 +461,6 @@
format(user_error,'~N; Done translating ~w forms: ~q.',
[TF,asserted_metta_pred(MangleP2,Filename)]))).

write_src_woi(Term):- with_indents(false,write_src(Term)).

% write comments
write_metta_datalog_term(Output,'$COMMENT'(Term,_,_),_MangleP2,_Lineno):-
format(Output,"/* ~w */~n",[Term]).
Expand Down
2 changes: 1 addition & 1 deletion src/canary/metta_pfc_base.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@

pfc_eval_rhs1(Assertion,Support) :-
% an assertion to be added.
once_writeq_ln(pfcRHS(Assertion)),
once_writeq_nl(pfcRHS(Assertion)),
(must_ex(pfcPost1(Assertion,Support))*->true ;
pfcWarn("Malformed rhs of a rule: ~p",[Assertion])).

Expand Down
10 changes: 7 additions & 3 deletions src/canary/metta_printer.pl
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,13 @@
py_is_enabled:- predicate_property(py_ppp(_),defined), asserta((py_is_enabled:-!)).

%write_src(V):- !, \+ \+ quietly(pp_sex(V)),!.
write_src(V):- \+ \+ notrace(pp_sex(V)),!.
write_src_woi_ln(X):-
format('~N'),write_src_woi(X),format('~N').
write_src(V):- \+ \+ notrace((
guess_metta_vars(V),pp_sex(V))),!.
write_src_woi(Term):-
notrace((with_indents(false,write_src(Term)))).
write_src_woi_nl(X):- \+ \+
notrace((guess_metta_vars(X),
format('~N'),write_src_woi(X),format('~N'))).


pp_sex(V):- pp_sexi(V),!.
Expand Down
22 changes: 21 additions & 1 deletion src/canary/metta_space.pl
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@
has_type(S,Type):- sub_atom(S,0,4,Aft,FB),flybase_identifier(FB,Type),!,Aft>0.


call_sexpr(S):- once_writeq_ln(call_sexpr(S)).
call_sexpr(S):- once_writeq_nl(call_sexpr(S)).
%call_sexpr(Space,Expr,Result):-

:- dynamic(fb_pred/2).
Expand Down Expand Up @@ -666,4 +666,24 @@
symbolic_list_concat(A,B):- atomic_list_concat(A,B).
symbol_contains(T,TT):- atom_contains(T,TT).
*/
search_for1(X):-
forall((metta_atom(_Where,What),contains_var(X,What)),
write_src_nl(What)).

search_for2(X):-
forall((metta_src(_Where,What),contains_var(X,What)),
write_src_woi_nl(What)).


metta_src(Where,What):-
loaded_into_kb(Where,File), metta_file_buffer(_,What,Vars,File,_Loc),
ignore(maplist(name_the_var,Vars)).


name_the_var(N=V):- ignore((atom_concat('_',NV,N),V='$VAR'(NV))).
guess_metta_vars(What):-
ignore(once((metta_file_buffer(_,What0,Vars,_File,_Loc),
alpha_unif(What,What0),
maplist(name_the_var,Vars)))).

alpha_unif(What,What0):- What=@=What0,What=What0.
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
timeout: failed to run command 'time': No such file or directory
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
timeout: failed to run command 'time': No such file or directory
[()]
[()]
[()]
[()]
[()]
[()]
[()]
[]
0.11user 0.01system 0:00.12elapsed 99%CPU (0avgtext+0avgdata 26552maxresident)k
560inputs+0outputs (5major+3377minor)pagefaults 0swaps

0 comments on commit 8949194

Please sign in to comment.