Skip to content

Commit 0c9819f

Browse files
committed
Fixes for tests/QC-precommit/pln-inf-ctl.metta
1 parent 97fcb11 commit 0c9819f

File tree

9 files changed

+69
-41
lines changed

9 files changed

+69
-41
lines changed

prolog/metta_lang/metta_compiler.pl

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@
264264
as_p1_exec(ispeEn(ERet,ECode,_),ERet) :- !, call(ECode).
265265
as_p1_exec(ispeEnN(ERet,ECode,_,_),ERet) :- !, call(ECode).
266266
as_p1_exec(ispeEnNC(ERet,ECode,_,_,CCode),ERet) :- !, call(CCode),call(ECode).
267+
as_p1_exec(rtrace(T),TRet) :- !, rtrace(as_p1_exec(T,TRet)).
268+
as_p1_exec(call(P1,T),TRet) :- !, call(P1,as_p1_exec(T,TRet)).
269+
%as_p1_exec(X,Y) :- as_p1_expr(X,S),eval(S,Y).
267270
as_p1_exec(X,X) :- !.
268271

269272
as_p1_expr(X,X) :- \+ compound(X), !.
@@ -272,6 +275,8 @@
272275
as_p1_expr(ispeEn(_,_,NRet),NRet).
273276
as_p1_expr(ispeEnN(_,_,NRet,NCode),NRet) :- !, call(NCode).
274277
as_p1_expr(ispeEnNC(_,_,NRet,NCode,CCode),NRet) :- !,call(CCode),call(NCode).
278+
as_p1_expr(rtrace(T),TRet) :- !, rtrace(as_p1_expr(T,TRet)).
279+
as_p1_expr(call(P1,T),TRet) :- !, call(P1,as_p1_expr(T,TRet)).
275280
as_p1_expr(X,X) :- !.
276281

277282
create_p1(URet,[],[ispu,URet]) :- !.
@@ -516,16 +521,16 @@
516521
subst001(X,E,_,XX),unnumbervars_wco(XX,XXX).
517522
unnumbervars_wco(X,X).
518523

519-
% max_integer_in_term(+Term, -Max)
520-
max_integer_in_term(Term, Start, Max) :-
524+
% max_var_integer_in_term(+Term, -Max)
525+
max_var_integer_in_term(Term, Start, Max) :-
521526
Box = box(Start), % Correct initialization
522-
forall( ( sub_term_safely(Int, Term), integer(Int), ( box(Int) @> Box )),
527+
forall( ( sub_term_safely(CmpdVar, Term), compound(CmpdVar), CmpdVar = '$VAR'(Int), integer(Int), ( box(Int) @> Box )),
523528
nb_setarg(1, Box, Int)),
524529
arg(1, Box, Max),!.
525530

526531
number_vars_wo_conficts(X,XX):-
527532
copy_term(X,XX),
528-
woct(max_integer_in_term(XX,0,N)),
533+
woct(max_var_integer_in_term(XX,0,N)),
529534
succ(N,N2),
530535
numbervars(XX,N2,_,[attvar(skip)]).
531536

@@ -1990,7 +1995,7 @@
19901995
create_prefixed_name('mc_',LenArgs,Fn,FnWPrefix),
19911996
sum_list(LenArgs,LenArgsTotal),
19921997
LenArgsTotalPlus1 is LenArgsTotal+1,
1993-
functor(Info,FnWPrefix,LenArgsTotalPlus1),
1998+
functor_chkd(Info,FnWPrefix,LenArgsTotalPlus1),
19941999
skip_redef_head(user,Info),!.
19952000

19962001
into_fa(Fn/[Arity],Fn,Arity):- must_be(number,Arity).
@@ -2034,7 +2039,7 @@
20342039
label_arg_types(F,N2,Args).
20352040

20362041
% label_arg_n_type(F,0,A):- !, label_type_assignment(A,F).
2037-
label_arg_n_type(F,N,A):- compound(F),functor(F,Fn,Add),Is is Add+N, !, label_arg_n_type(Fn,Is,A).
2042+
label_arg_n_type(F,N,A):- compound(F),functor_chkd(F,Fn,Add),Is is Add+N, !, label_arg_n_type(Fn,Is,A).
20382043
label_arg_n_type(F,N,A):- add_type_to(A,arg(F,N)),!.
20392044

20402045
add_type_to(V,T):- is_list(T), !, maplist(add_type_to(V),T).
@@ -2361,7 +2366,7 @@
23612366
in_type_set(Set,Type):- Set==Type,!.
23622367
in_type_set(Set,Type):- compound(Set),arg(_,Set,Arg),in_type_set(Arg,Type).
23632368

2364-
b_put_set(Set,Type):- functor(Set,_,Arg),!,b_put_nset(Set,Arg,Type).
2369+
b_put_set(Set,Type):- functor_chkd(Set,_,Arg),!,b_put_nset(Set,Arg,Type).
23652370
b_put_nset(Set,_,Type):- in_type_set(Set,Type),!.
23662371
b_put_nset(Set,N,Type):- arg(N,Set,Arg),
23672372
(compound(Arg)->b_put_set(Arg,Type);b_setarg(N,Set,[Type|Arg])).
@@ -2428,15 +2433,15 @@
24282433
append_sets(RefsL,Refs):- flatten(RefsL,Flat),list_to_set(Flat,Refs).
24292434
compiled_info_s(S,Refs):-
24302435
findall(Ref,(compiler_data(F/A),compiled_refs(S,F,A,Ref)),RefsL),append_sets(RefsL,Refs1),
2431-
findall(Ref,(current_predicate(S/A),functor(P,S,A),clause(P,_,Ref)),Refs2),append_sets([Refs1,Refs2],Refs).
2436+
findall(Ref,(current_predicate(S/A),functor_chkd(P,S,A),clause(P,_,Ref)),Refs2),append_sets([Refs1,Refs2],Refs).
24322437
compiled_info_f(F,Refs):- compiled_info_s(F,Refs1), compiled_info_p(F,Refs2),append_sets([Refs1,Refs2],Refs).
24332438
compiled_info_p(F,Refs):-
2434-
findall(Ref,(current_predicate(F/A),functor(P,F,A),current_module(M),
2439+
findall(Ref,(current_predicate(F/A),functor_chkd(P,F,A),current_module(M),
24352440
\+ \+ predicate_property(M:P,_), \+ predicate_property(M:P,imported_from(_)),
24362441
clause(M:P,_,Ref)),Refs).
24372442

24382443
compiled_refs(Symbol,F,A,Info):-
2439-
functor(P,F,A),clause(P,B,Ref), (\+ compiler_data_no_call(F/A) -> call(B)), symbol_in(2,Symbol,P),
2444+
functor_chkd(P,F,A),clause(P,B,Ref), (\+ compiler_data_no_call(F/A) -> call(B)), symbol_in(2,Symbol,P),
24402445
(B==true->Info=Ref;Info=P).
24412446

24422447

@@ -2478,7 +2483,7 @@
24782483
transpile_call_prefix(Fn,Arity,CFn),
24792484

24802485
((current_predicate(CFn/Arity) -> true ;
2481-
must_det_lls((( functor(CallP,CFn,Arity),
2486+
must_det_lls((( functor_chkd(CallP,CFn,Arity),
24822487
CallP @.. [CFn|Args],
24832488
transpile_impl_prefix(Fn,Arity,IFn),
24842489
CallI @.. [IFn|Args],
@@ -2504,7 +2509,7 @@
25042509
prefix_impl_preds('mc__1_',F,A):- is_transpile_call_prefix(F,A,Fn),current_predicate(Fn/A), \+ prefix_impl_preds_pp(_,F,A).
25052510
prefix_impl_preds('mi__1_',F,A):- is_transpile_impl_prefix(F,A,Fn),current_predicate(Fn/A), \+ prefix_impl_preds_pp(_,F,A).
25062511

2507-
prefix_impl_preds_pp(Prefix,F,A):- predicate_property('mc__1_2_:'(_,_,_),file(File)),predicate_property(Preds,file(File)),functor(Preds,Fn,A),
2512+
prefix_impl_preds_pp(Prefix,F,A):- predicate_property('mc__1_2_:'(_,_,_),file(File)),predicate_property(Preds,file(File)),functor_chkd(Preds,Fn,A),
25082513
((transpile_impl_prefix(Prefix);transpile_call_prefix(Prefix)),atom_list_concat([Prefix,_FNArity,'_',F],Fn)).
25092514

25102515
maplist_and_conj(_,A,B):- fullvar(A),!,B=A.
@@ -2543,7 +2548,7 @@
25432548
extract_caller(H:-_,CallerInt,CallerSz):- !, extract_caller(H,CallerInt,CallerSz).
25442549
extract_caller([=,H,_],CallerInt,CallerSz):- !, extract_caller(H,CallerInt,CallerSz).
25452550
extract_caller(P,F,A):- \+ callable(P),!, F=P,A=0.
2546-
extract_caller(P,F,A):- \+ is_list(P), functor(P,F,A).
2551+
extract_caller(P,F,A):- \+ is_list(P), functor_chkd(P,F,A).
25472552

25482553

25492554
maybe_lazy_list(_,_,_,[],[]):-!.
@@ -2908,7 +2913,7 @@
29082913
transpile_call_prefix(Fn,CFn),
29092914
%trace,
29102915
((current_predicate(CFn/Arity) -> true ;
2911-
must_det_lls((( functor(CallP,CFn,Arity),
2916+
must_det_lls((( functor_chkd(CallP,CFn,Arity),
29122917
CallP @.. [CFn|Args],
29132918
transpile_impl_prefix(Fn,IFn),
29142919
CallI @.. [IFn|Args],
@@ -2922,7 +2927,7 @@
29222927
prefix_impl_preds('mc__',F,A):- is_transpile_call_prefix(F,Fn),current_predicate(Fn/A), \+ prefix_impl_preds_pp(_,F,A).
29232928
prefix_impl_preds('mi__',F,A):- is_transpile_impl_prefix(F,Fn),current_predicate(Fn/A), \+ prefix_impl_preds_pp(_,F,A).
29242929
2925-
prefix_impl_preds_pp(Prefix,F,A):- predicate_property('mc__:'(_,_,_),file(File)),predicate_property(Preds,file(File)),functor(Preds,Fn,A),
2930+
prefix_impl_preds_pp(Prefix,F,A):- predicate_property('mc__:'(_,_,_),file(File)),predicate_property(Preds,file(File)),functor_chkd(Preds,Fn,A),
29262931
((transpile_impl_prefix(Prefix);transpile_call_prefix(Prefix)),atom_concat(Prefix,F,Fn)).
29272932
29282933
maplist_and_conj(_,A,B):- fullvar(A),!,B=A.
@@ -2961,7 +2966,7 @@
29612966
extract_caller(H:-_,CallerInt,CallerSz):- !, extract_caller(H,CallerInt,CallerSz).
29622967
extract_caller([=,H,_],CallerInt,CallerSz):- !, extract_caller(H,CallerInt,CallerSz).
29632968
extract_caller(P,F,A):- \+ callable(P),!, F=P,A=0.
2964-
extract_caller(P,F,A):- \+ is_list(P), functor(P,F,A).
2969+
extract_caller(P,F,A):- \+ is_list(P), functor_chkd(P,F,A).
29652970
29662971
29672972
maybe_lazy_list(_,_,_,[],[]):-!.
@@ -3017,18 +3022,18 @@
30173022
catch(quietly(as_tf(apply(F,List),R)),error(existence_error(procedure,F/_),_),
30183023
quietly(catch(eval_args([F|List],R),_, R=[F|List])))).
30193024

3020-
%u_assign([V|VI],[V|VO]):- nonvar(V),is_metta_data_functor(_Eq,V),!,maplist(eval_args,VI,VO).
3025+
%u_assign([V|VI],[V|VO]):- nonvar(V),is_metta_data_functor_chkd(_Eq,V),!,maplist(eval_args,VI,VO).
30213026

30223027
u_assign_c((F:-List),R):- !, R = (F:-List).
30233028

30243029
/*
30253030
u_assign_c(Cmp,RR):-
3026-
functor(Cmp,F,_),
3031+
functor_chkd(Cmp,F,_),
30273032
current_predicate(F,_),
30283033
debug(todo,'u_assign_c INTERP: ~q',[Cmp]),!,
30293034
call(Cmp,RR).*/
30303035
u_assign_c(FList,RR):-
3031-
functor(FList,F,_), % (F == 'car-atom' -> trace ; true),
3036+
functor_chkd(FList,F,_), % (F == 'car-atom' -> trace ; true),
30323037
(catch(quietlY(call(FList,R)),error(existence_error(procedure,F/_),_),
30333038
catch(quietlY(as_tf(FList,R)),error(existence_error(procedure,F/_),_),
30343039
((p2m(FList,[F0|List0]),catch(eval_args([F0|List0],R),_, R=~[F0|List0])))))),!,
@@ -3397,7 +3402,7 @@
33973402
compile_flow_control2(HeadIs, LazyVars, RetResult, ResultLazy, Convert, Converted).
33983403

33993404
compile_flow_control2(HeadIs, LazyVars, _Result, ResultLazy, Convert, Converted) :- fail,
3400-
functor(Convert,Func,PA),
3405+
functor_chkd(Convert,Func,PA),
34013406
functional_predicate_arg(Func,PA,Nth),
34023407
Convert =~ [Func|PredArgs],
34033408
nth1(Nth,PredArgs,Result,FuncArgs),
@@ -3430,7 +3435,7 @@
34303435
strip_m(HH,HHH),HHH=@=H2,
34313436
strip_m(BB,BBB),BBB=@=B,!.
34323437

3433-
%get_clause_pred(UAC,F,A):- expand_to_hb(UAC,H,_),strip_m(H,HH),functor(HH,F,A).
3438+
%get_clause_pred(UAC,F,A):- expand_to_hb(UAC,H,_),strip_m(H,HH),functor_chkd(HH,F,A).
34343439

34353440

34363441
% :- dynamic(needs_tabled/2).
@@ -3753,7 +3758,7 @@
37533758
pi(PI):- PI is pi.
37543759

37553760
% Retrieve Head of the List
3756-
'car-atom'(List, Head):- eval_H(['car-atom', List], Head).
3761+
% 'car-atom'(List, Head):- eval_H(['car-atom', List], Head).
37573762

37583763

37593764
% Mapping any current predicate F/A to a function, if it's not tricky
@@ -3767,7 +3772,7 @@
37673772
predicate_arity(F,A):- current_predicate(F/A).
37683773
% Certain constructs should not be converted to functions.
37693774
not_function(P):- atom(P),!,not_function(P,0).
3770-
not_function(P):- callable(P),!,functor(P,F,A),not_function(F,A).
3775+
not_function(P):- callable(P),!,functor_chkd(P,F,A),not_function(F,A).
37713776
not_function(F,A):- is_arity_0(F,FF),!,not_function(FF,A).
37723777
not_function(!,0).
37733778
not_function(print,1).
@@ -3784,7 +3789,7 @@
37843789
not_function('True',0).
37853790
not_function(F,A):- predicate_arity(F,A),AA is A+1, \+ decl_functional_predicate_arg(F,AA,_).
37863791

3787-
needs_call_fr(P):- is_function(P,_Nth),functor(P,F,A),AA is A+1, \+ current_predicate(F/AA).
3792+
needs_call_fr(P):- is_function(P,_Nth),functor_chkd(P,F,A),AA is A+1, \+ current_predicate(F/AA).
37883793

37893794
is_control_structure(F,A):- atom(F), atom_concat('if-',_,F),A>2.
37903795

@@ -3803,7 +3808,7 @@
38033808
is_function(AsFunction, Nth) :- is_arity_0(AsFunction,_), !,Nth=1.
38043809
is_function(AsFunction, Nth) :-
38053810
callable(AsFunction),
3806-
functor(AsFunction, Functor, A),
3811+
functor_chkd(AsFunction, Functor, A),
38073812
\+ not_function(Functor, A),
38083813
AA is A + 1,
38093814
functional_predicate_arg_maybe(Functor, AA, Nth).
@@ -4139,9 +4144,9 @@
41394144
nonvar(AsFunction),
41404145
compound(AsFunction),
41414146
\+ is_arity_0(AsFunction,_),
4142-
functor(AsFunction,F,A),
4147+
functor_chkd(AsFunction,F,A),
41434148
HeadIs\=@=AsFunction,
4144-
\+ (compound(HeadIs), (is_arity_0(HeadIs,HF);functor(HeadIs,HF,_))-> HF==F),
4149+
\+ (compound(HeadIs), (is_arity_0(HeadIs,HF);functor_chkd(HeadIs,HF,_))-> HF==F),
41454150
(into_x_assign(AsFunction, Result,AsPred)
41464151
-> true
41474152
; (AA is A+1,
@@ -4284,15 +4289,15 @@
42844289
% Converts a given predicate AsPred to its equivalent function term AsFunction
42854290
pred_to_funct(AsPred, AsFunction, Result) :-
42864291
compound(AsPred), % Checks if AsPred is a compound term
4287-
functor(AsPred, F, A), % Retrieves the functor F and arity A of AsPred
4292+
functor_chkd(AsPred, F, A), % Retrieves the functor F and arity A of AsPred
42884293
functional_predicate_arg(F, A, Nth),!, % Finds the Nth argument where the result should be
42894294
arg(Nth, AsPred, Result), % Retrieves the result from the Nth argument of AsPred
42904295
remove_funct_arg(AsPred, Nth, AsFunction). % Constructs the function AsFunction by removing the Nth argument from AsPred
42914296

42924297
% If not found in functional_predicate_arg/3, it tries to construct AsFunction by removing the last argument from AsPred
42934298
pred_to_funct(AsPred, AsFunction, Result) :-
42944299
compound(AsPred), !,
4295-
functor(AsPred, _, Nth),
4300+
functor_chkd(AsPred, _, Nth),
42964301
arg(Nth, AsPred, Result),
42974302
remove_funct_arg(AsPred, Nth, AsFunction).
42984303

@@ -4314,7 +4319,7 @@
43144319
findall(Head, member((Head:-_), HeadBodiesList), Heads),
43154320
% Find the least general head among the collected Heads
43164321
least_general_head(Heads, LeastHead),
4317-
functor(LeastHead,F,A),functor(NewHead,F,A),
4322+
functor_chkd(LeastHead,F,A),functor_chkd(NewHead,F,A),
43184323
% Transform and combine bodies according to the new head found
43194324
transform_and_combine_bodies(HeadBodiesList, NewHead, NewCombinedBodies)),
43204325
\+ \+ (
@@ -4339,9 +4344,9 @@
43394344
% This predicate is conceptual and will require more complex processing depending on the actual structures of the heads.
43404345
generalization(Head1, Head2, GeneralizedHead) :-
43414346
% Ensure the functor names and arities are the same between Head1 and Head2.
4342-
functor(Head1, Name, Arity),
4343-
functor(Head2, Name, Arity),
4344-
functor(GeneralizedHead, Name, Arity),
4347+
functor_chkd(Head1, Name, Arity),
4348+
functor_chkd(Head2, Name, Arity),
4349+
functor_chkd(GeneralizedHead, Name, Arity),
43454350
% Generalize the arguments of the heads.
43464351
generalize_args(Arity, Head1, Head2, GeneralizedHead).
43474352

prolog/metta_lang/metta_compiler_lib.pl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -682,13 +682,13 @@
682682

683683

684684

685-
:- initialization(setup_library_call(builtin, 'metta-equals', [2], '@doc', '@doc', [x(noeval,eager,[]), x(noeval,eager,[])], x(doeval,eager,[boolean])), program).
685+
transpiler_predicate_store(builtin, 'metta-equals', [2], '@doc', '@doc', [x(noeval,eager,[]), x(noeval,eager,[])], x(doeval,eager,[boolean])).
686686
'mc__1_2_metta-equals'(A,B,TF):- as_tf(A=@=B,TF).
687687

688-
:- initialization(setup_library_call(builtin, 'metta-unify', [2], '@doc', '@doc', [x(noeval,eager,[]), x(noeval,eager,[])], x(doeval,eager,[boolean])), program).
688+
transpiler_predicate_store(builtin, 'metta-unify', [2], '@doc', '@doc', [x(noeval,eager,[]), x(noeval,eager,[])], x(doeval,eager,[boolean])).
689689
'mc__1_2_metta-unify'(A,B,TF):- as_tf(unify_with_occurs_check(A,B),TF).
690690

691-
:- initialization(setup_library_call(builtin, 'decons-ht', [3], '@doc', '@doc', [x(noeval,eager,[]),x(noeval,eager,[]),x(noeval,eager,[])],x(doeval,eager,[boolean])), program).
691+
transpiler_predicate_store(builtin, 'decons-ht', [3], '@doc', '@doc', [x(noeval,eager,[]),x(noeval,eager,[]),x(noeval,eager,[])],x(doeval,eager,[boolean])).
692692
'mc__1_3_decons-ht'(E,H,T,TF):- check_type_error( \+ iz_conz(E), 'decons-ht'(E,H,T)), as_tf(unify_with_occurs_check(E,[H|T]),TF).
693693

694694
transpiler_predicate_nary_store(builtin, 'py-atom-call', 1, ['Atom'], 'Atom', 'Atom', [x(doeval,eager,[])], x(doeval,eager,[]), x(doeval,eager,[])).

prolog/metta_lang/metta_debug.pl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,8 @@
804804

805805
sub_var_safely(Sub,Source):- assertion(acyclic_term(Source)),woct(sub_var(Sub,Source)).
806806
sub_term_safely(Sub,Source):- assertion(acyclic_term(Source)),woct(sub_term(Sub,Source)).
807+
functor_chkd(P,F,A):- compound(P),!,compound_name_arity(P,F,AA), if_t(A==0, (bt, prolog)), if_t(AA==0, (bt, prolog)), A=AA.
808+
functor_chkd(P,F,A):- functor(P,F,A), if_t(A==0, (bt, prolog)).
807809

808810
maybe_abort_trace:- \+ is_flag(abort_trace), !.
809811
maybe_abort_trace:- abort_trace.

prolog/metta_lang/metta_eval.pl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,8 +1692,16 @@
16921692
eval_20(_Eq,_RetType,_Depth,_Self,['=alpha', X,Y],TF):- !,
16931693
as_tf('=alpha'(X,Y),TF).
16941694

1695+
lmax_var_number(V, Max, Max) :- \+ compound(V), !.
1696+
lmax_var_number(V, Max, Max) :- compound_name_arity(V,_,0), !.
1697+
lmax_var_number('$VAR'(I), Max0, Max) :- integer(I), !, Max is max(I, Max0).
1698+
lmax_var_number(S, Max0, Max) :- functor(S, _, Ar), lmax_var_numberl(Ar, S, Max0, Max).
1699+
lmax_var_numberl(0, _, Max, Max) :- !.
1700+
lmax_var_numberl(I, T, Max0, Max) :- arg(I, T, Arg),
1701+
I2 is I+ -1, lmax_var_number(Arg, Max0, Max1), lmax_var_numberl(I2, T, Max1, Max).
1702+
16951703
equal_renumbered(X0,Y0,XX,YY):-
1696-
max_var_number(X0+Y0,0,N),succ(N,N2),
1704+
lmax_var_number(X0+Y0,0,N),succ(N,N2),
16971705
copy_term(X0+Y0,X+Y),
16981706
term_variables(X,VXs), term_variables(Y,VYs),
16991707
merge_same_named_vars(VXs,VYs,Same,Merges,LOXVs,LOYVs),
@@ -1709,7 +1717,7 @@
17091717

17101718
renumber_vars_wo_confict_tu(X,XXX):-
17111719
copy_term(X,XX),
1712-
max_var_number(XX,0,N),
1720+
lmax_var_number(XX,0,N),
17131721
succ(N,N2),
17141722
numbervars(XX,N2,_,[attvar(skip)]), % TODO
17151723
unnumbervars_wco123(XX,XXX).

prolog/metta_lang/metta_interp.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7704,7 +7704,7 @@
77047704
debug_info(always(do_metta),do_metta_runtime(Var, Call)),
77057705
original_user_error(Err),
77067706
% Extract the functor name from the goal (`Call`) to create a description.
7707-
functor(Call, Func, _),
7707+
functor_chkd(Call, Func, _),
77087708
atom_concat('Testing ', Func, Description),
77097709
% Record the start times (wall clock and CPU time).
77107710
current_times(WallStart, CPUStart),

prolog/metta_lang/metta_loader.pl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,7 @@
820820
% % Import a Python module named "example_py_module" into the Prolog environment.
821821
% ?- import_metta1('&self', 'example_py_module').
822822
%
823+
import_metta1(_Slf, Module) :- nonvar(Module), assumed_loaded(Module),!.
823824
import_metta1(Self, Module) :- maybe_into_top_self(Self, TopSelf), !, import_metta1(TopSelf, Module).
824825
import_metta1(Self, Module):-
825826
% If the Module is a valid Python module, extend the current Prolog context with Python.

prolog/metta_lang/metta_parser.pl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,11 @@
10681068
read_list('}', Stream, List),
10691069
univ_list_to_item(List,Item).
10701070

1071+
% If '<', read an S-expression list.
1072+
cont_sexpr_from_char(_EndChar, Stream, '<', Item) :- prolog_term_start('<'),
1073+
read_list('>', Stream, List),
1074+
univ_list_to_item(List,Item).
1075+
10711076
% If '[', '{', etc. - using paren_pair_functor
10721077
cont_sexpr_from_char(_EndChar, Stream, Char, Item) :- paren_pair_functor(Char, EndOfParen, Functor),
10731078
read_list(EndOfParen, Stream, It3m),

prolog/metta_lang/metta_printer.pl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1911,12 +1911,15 @@
19111911

19121912

19131913
compound_type_s_m_e(list,'(','.',')').
1914-
compound_type_s_m_e(cmpd,S,E,M):- !, prolog_term_start(S),compound_type_s_m_e(ocmpd,S,E,M),!.
1914+
compound_type_s_m_e(cmpd,S,E,M):- prolog_term_start(S),compound_type_s_m_e(ocmpd,S,E,M),!.
19151915
compound_type_s_m_e(ocmpd,'#(','.',')').
19161916
compound_type_s_m_e(ocmpd,'[','|',']').
19171917
compound_type_s_m_e(ocmpd,'{','|','}').
19181918
compound_type_s_m_e(ocmpd,'(','@',')').
19191919

1920+
%prolog_term_start(_):- fail.
1921+
%prolog_term_start('#(').
1922+
%prolog_term_start('{').
19201923
prolog_term_start('[').
19211924

19221925
paren_pair_functor('(',')',_).

prolog/metta_lang/metta_python.pl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1899,7 +1899,7 @@
18991899
(nonvar(File) -> Use = File ; Use = Module),
19001900
pybug('extend-py!'(Use)),
19011901
% py_call_warg(mettalog:use_mettalog()),
1902-
(Use == mettalog -> true ; py_load_modfile(Use)),
1902+
(assumed_loaded(Use) -> true ; py_load_modfile(Use)),
19031903
% listing(ensure_rust_metta/1),
19041904
% ensure_mettalog_py,
19051905
nb_setval('$py_ready','true'),
@@ -1912,6 +1912,10 @@
19121912
% py_call_warg(MeTTa:load_py_module(ToPython),Result),
19131913
true)),!.
19141914

1915+
1916+
assumed_loaded(mettalog).
1917+
assumed_loaded(random).
1918+
19151919
%! py_load_modfile(+Use) is det.
19161920
%
19171921
% Loads a Python module file into the current environment by calling the mettalog

0 commit comments

Comments
 (0)