On 11/06/2014, at 19:50, Gesche Gierse <gierse_at_kbsg.rwth-aachen.de> wrote: > Thanks for the help, that solution works out fine. > > However it raises another questions: I need to store those dynamic > predicates in different files (want to use some with different modules > and avoid copy&paste). Furthermore I want to load that definitions only > with a single import/use_module call. > > When I load these predicates with > > :- ['outsourced_predicates'] > > the solution below does not detect the predicates defined in > "outsourced_predicates" (they seem to be unfindable for "clause"). > > I hacked that by defining a module "outsourced_predicates", which has a > tool predicate "assert_preds", that asserts everything to the calling > module: > > :- export assert_preds/0. > :- tool(assert_preds/0, assert_preds/1). > > assert_preds(M) :- call(assert(..))@M. > > That works, but I have to call the predicate "assert_preds" explicitly. > I would rather like to call it implicitly at import time. Therefore I tried > > :- export initialization((outsourced_predicates : assert_preds)) > > However, then "clause" does not detect the asserted predicates. > > Do you have any idea how I could use definitions from different files > such that "clause" can find all of them in one module and that only one > import command is needed? Lookup the documentation on multifile predicates. Cheers, Paulo > On 2014-05-29 13:20, Joachim Schimpf wrote: >> On 29/05/2014 11:48, Marco Gavanelli wrote: >>> Dear Gesche, >>> >>> Maybe you could use abolish/1 to remove the dynamic predicate and then >>> use compile_term/1 to re-add the predicate in compiled form. >>> >>> Example: >>> ------------------------------------------------------------------ >>> [eclipse 1]: assert(p:-q). >>> >>> Yes (0.00s cpu) >>> [eclipse 2]: compile_term(q). >>> source_processor.eco loaded in 0.00 seconds >>> ... >>> ecl_compiler.eco loaded in 0.05 seconds >>> >>> Yes (0.05s cpu) >>> [eclipse 3]: clause(p,X). >>> >>> X = q >>> Yes (0.00s cpu) >>> [eclipse 4]: abolish(p/0). >>> >>> Yes (0.00s cpu) >>> [eclipse 5]: p. >>> calling an undefined procedure p in module eclipse >>> Abort >>> [eclipse 6]: compile_term(p:-q). >>> >>> Yes (0.00s cpu) >>> [eclipse 7]: clause(p,X). >>> procedure not dynamic in clause(p, X) in module eclipse >>> Abort >>> [eclipse 8]: p. >>> >>> Yes (0.00s cpu) >>> --------------------------------------------------------------------- >> >> >> Correct. Here is a little utility that does everything: >> >> :- tool(dynamic_to_static/1, dynamic_to_static_/2). >> dynamic_to_static_(F/N, Module) :- >> functor(Head, F, N), >> findall(Head:-Body, clause(Head, Body), Clauses)@Module, >> abolish(F/N)@Module, >> compile_term(Clauses)@Module. >> >> >> ?- assert(p(111)), assert(p(222)). >> Yes (0.00s cpu) >> >> ?- dynamic_to_static(p/1). >> Yes (0.00s cpu) >> >> ?- is_dynamic(p/1). >> No (0.00s cpu) >> >> ?- p(X). >> X = 111 >> Yes (0.00s cpu, solution 1, maybe more) >> X = 222 >> Yes (0.02s cpu, solution 2) >> >> >> -- Joachim >> >> >> ------------------------------------------------------------------------------ >> Time is money. Stop wasting it! Get your web API in 5 minutes. >> www.restlet.com/download >> http://p.sf.net/sfu/restlet >> _______________________________________________ >> ECLiPSe-CLP-Users mailing list >> ECLiPSe-CLP-Users_at_lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users >> > > > ------------------------------------------------------------------------------ > HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions > Find What Matters Most in Your Big Data with HPCC Systems > Open Source. Fast. Scalable. Simple. Ideal for Dirty Data. > Leverages Graph Analysis for Fast Processing & Easy Data Exploration > http://p.sf.net/sfu/hpccsystems > _______________________________________________ > ECLiPSe-CLP-Users mailing list > ECLiPSe-CLP-Users_at_lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/eclipse-clp-users ----------------------------------------------------------------- Paulo Moura Logtalk developer Email: <mailto:pmoura_at_logtalk.org> Web: <http://logtalk.org/> -----------------------------------------------------------------Received on Thu Jun 12 2014 - 01:15:45 CEST
This archive was generated by hypermail 2.2.0 : Thu Jun 12 2014 - 18:13:13 CEST