Re: predutils package available (Re: PAC library for develop version available)
Kuniaki Mukai <[email protected]> Fri, 3 Oct 2014 00:35:23 +0900
| Newsgroups | gmane.comp.ai.prolog.swi |
|---|---|
| Message-ID | <[email protected]> |
Hi Jan, On Oct 2, 2014, at 23:23, Jan Wielemaker <[email protected]> wrote: > On 10/02/2014 02:31 PM, Kuniaki Mukai wrote: >>>> Writing libraries is a different thing than writing a program in user >>>> space ... I hope this helps > >> Deep words. I feel I have seen something of library builder's invisible efforts >> for others happy life. > > On the other hand, writing libraries isn't too different from writing > large application where you need code structuring. Once you get the > hang of it, the extra structuring rules help you more than they hinder > you. > >> By the way, I would like to ask you an urgent and maybe stupid >> question about module. I thought exported names can be used from any >> oother contexts, i.e., globally, like builtin append/3. But a simple >> experiment shows that it is not the case. So my question is: in >> what contexts an exported name can be used without putting module >> prefix before the name ? I have read the recommended document, but I am >> afraid I have missed the point again. > > For most Prolog systems, a use_module/1 means you can use the code from > the module you are importing from only. SWI-Prolog modules have a notion > of `default modules`: if a predicate cannot be found in a module, it will > try its default module (recursively). All modules default to `user`, while > `user` defaults to `system`. So, code that you write in (or import into) > user is visible in all modules, but can be locally overruled. B.t.w., > system library files default directly to `system`, so you cannot modify > their behaviour by writing things in `user`. Operator inheritance follows > the same rules. > > The defaulting scheme can be modified, which allows for defining other > visibility and reuse models. Thank you for your clear answer. However, to be honest, what I wanted to know is something on opposite direction of the 'default'. Although your answer has made me clear, let me put my intended question in more concrete way. Suppose two module files "mod_a.pl" and a `child` module "mod_b.pl" defined as follow: %%%% file mod_a.pl %%% :- module(mod_a, [hello/0]). :- use_module(mod_b). hello :- writeln('hello from ma.'). %%%% file mod_b.pl %%% :- module(mod_b, [world/0]). world :- writeln('world from mb'). % ls mod_b.pl mod_a.pl So setting the situation, I got the log below. Of course, that log is what everyone expects except me. % swipl Welcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.1.23-28-g70f014a) Copyright (c) 1990-2014 University of Amsterdam, VU Amsterdam SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. Please visit http://www.swi-prolog.org for details. For help, use ?- help(Topic). or ?- apropos(Word). ?- use_module(mod_a). true. ?- hello. hello from ma. true. ?- world. Correct to: "mod_b:world"? Please answer 'y' or 'n'? ERROR: '$execute_goal2'/2: Undefined procedure: world/0 ERROR: However, there are definitions for: ERROR: mod_a:world/0 ERROR: mod_b:world/0 Exception: (6) world ? abort % Execution Aborted I believed wrongly that imported predicates from "child modules" may get global under some context. In fact, I expected no error message for that query. My question was really stupid, but I appreciate a lot for your taking time. I hope I am the only such a prologer. Kuniaki > > Cheers --- Jan > _______________________________________________ > SWI-Prolog mailing list > [email protected] > https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 496 bytes Desc: Message signed with OpenPGP using GPGMail URL: <https://lists.iai.uni-bonn.de/pipermail/swi-prolog/attachments/20141003/1d8d38f4/signature.asc>