Skip to content

Commit

Permalink
canary-90 use_corelib_file
Browse files Browse the repository at this point in the history
  • Loading branch information
TeamSPoon committed Aug 20, 2024
1 parent 8c9b830 commit 84cfbee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/canary/metta_corelib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

:- discontiguous metta_atom_corelib_types/1.

:- dynamic(using_corelib_file/0).


metta_atom_corelib_defn( [=, ['car-atom', A], [eval, ['if-decons', A, B, _, B, ['Error', ['car-atom', A], "car-atom expects a non-empty expression as an argument"]]]]).
metta_atom_corelib_defn( [=, ['cdr-atom', A], [eval, ['if-decons', A, _, B, B, ['Error', ['cdr-atom', A], "cdr-atom expects a non-empty expression as an argument"]]]]).
metta_atom_corelib_defn( [=, ['filter-atom', A, B, C], [function, [eval, ['if-decons', A, D, E, [chain, [eval, ['filter-atom', E, B, C]], F, [chain, [eval, [apply, D, B, C]], G, [chain, G, H, [eval, [if, H, [chain, [cons, D, F], I, [return, I]], [return, F]]]]]], [return, []]]]]]).
Expand Down Expand Up @@ -280,4 +283,15 @@
:- multifile(metta_atom_asserted_deduced/2).
metta_atom_asserted_deduced('&corelib', Term):- metta_atom_corelib_types(Term).

use_corelib_file:- using_corelib_file,!.
use_corelib_file:- asserta(using_corelib_file), fail.
use_corelib_file:- !.
use_corelib_file:- is_metta_dir(Dir), really_use_corelib_file(Dir,'corelib.metta'),!.
use_corelib_file:- is_metta_dir(Dir), really_use_corelib_file(Dir,'stdlib_mettalog.metta'),!.
% !(import! &corelib "src/canary/stdlib_mettalog.metta")
really_use_corelib_file(Dir,File):- absolute_file_name(File,Filename,[relative_to(Dir)]),
include_metta_directory_file('&corelib',Dir,Filename).

%:- initialization(use_corelib_file).


5 changes: 3 additions & 2 deletions src/canary/metta_eval.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2135,6 +2135,7 @@


:-if(true).
:- nodebug(metta('defn')).

eval_maybe_defn(Eq,RetType,Depth,Self,X,Res):-
\+ \+ (curried_arity(X,F,A),
Expand All @@ -2145,7 +2146,7 @@
\+ fail_on_constructor,
eval_constructor(Eq,RetType,Depth,Self,X,Res).
eval_maybe_defn(Eq,RetType,Depth,Self,X,Y):- can_be_ok(eval_maybe_defn,X),!,
trace_eval(eval_defn_choose_candidates(Eq,RetType),' find_defn ',Depth,Self,X,Y).
trace_eval(eval_defn_choose_candidates(Eq,RetType),'defn',Depth,Self,X,Y).

eval_constructor(Eq,RetType,Depth,Self,X,Res):-
eval_maybe_subst(Eq,RetType,Depth,Self,X,Res).
Expand Down Expand Up @@ -2185,7 +2186,7 @@

:-else.
eval_maybe_defn(Eq,RetType,Depth,Self,X,Y):- can_be_ok(eval_maybe_defn,X),!,
trace_eval(eval_defn_choose_candidates(Eq,RetType),' find_defn ',Depth,Self,X,Y).
trace_eval(eval_defn_choose_candidates(Eq,RetType),'defn',Depth,Self,X,Y).

eval_defn_choose_candidates(Eq,RetType,Depth,Self,X,Y):-
findall((XX->B0),get_defn_expansions(Eq,RetType,Depth,Self,X,XX,B0),XXB0L),
Expand Down
3 changes: 3 additions & 0 deletions src/canary/metta_interp.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,10 @@
%:- ensure_loaded(metta_python).


:- initialization(use_corelib_file).

:- ignore(((
use_corelib_file,
(is_testing -> UNIT_TEST=true; UNIT_TEST=false),
set_is_unit_test(UNIT_TEST),
\+ prolog_load_context(reloading,true),
Expand Down

0 comments on commit 84cfbee

Please sign in to comment.