diff --git a/q/dep/dep.q b/q/dep/dep.q index bcde3f6..65fbf76 100644 --- a/q/dep/dep.q +++ b/q/dep/dep.q @@ -179,6 +179,17 @@ if[()~key `.finos.dep.resolvers; .finos.dep.resolvers:(`$())!()]; .finos.dep.priv.unload each exec moduleName from .finos.dep.list; }; +.finos.dep.useModule:{[name] + while[(ns:`$8?.Q.A,.Q.a)in key`.finos]; + nsfull:.Q.dd[`.finos;ns]; + nsfull set orig:(``z`q`Q`finos#get`); + ({.finos.dep.loadModule x};name) . nsfull; + updated:get nsfull; + ![`.finos;();0b;enlist ns]; + newns:(key[updated]except key orig)#updated; + .finos.dep:updated[`finos;`dep]; + newns}; + .z.exit:{[handler;x] .finos.dep.priv.unloadAll[]; handler[x]}$[()~key `.z.exit; (::); .z.exit]; diff --git a/q/finos.q b/q/finos.q new file mode 100644 index 0000000..539ccdd --- /dev/null +++ b/q/finos.q @@ -0,0 +1,20 @@ +//system"l ",1_string .Q.rp`:.:finos_init.q; +system"l ",1_string .Q.rp`:::../finos_init.q; + +provide:{[x;a] + if[not (sm:string[x]) in key .finos.dep.list;'"module not registered: ",.Q.s1 x]; + n:` sv .z.M,`m,x; + path:.finos.dep.list[sm;`scriptPath]; + l:.Q.m.p1 ll:.Q.m.pl[enlist path;enlist x]; + if[0=count l; + -2 each enlist["tried the following paths:"]," ",/:ll; + '"notfound: ",string x]; + if[not null m:.Q.m.M[(p:.Q.m.dl l;`)]`m; + $[m~`:;'`cycle;:m]]; + r:.Q.m.ch[n;p;`;.Q.m.ld l;a]; + :[r;(0b;r); + [.Q.m.M[(p;`)]:enlist[`m]!enlist n;n]; + (1b;r); + 'r]} + +export:([provide])