[m-users.] Module include and undefined symbol.
Sean Charles (emacstheviking)
objitsu at gmail.com
Sat Aug 24 23:24:56 AEST 2024
Somedays I despair at my seeming lack of brain power, this is two of them.
OK, so I modified my code:
:- implementation.
:- import_module list.
:- import_module string.
:- import_module core.comments.
:- import_module core.stackops.
:- import_module dstack.
:- include_module comments.
:- include_module stackops.
And it has compiled. Hurrah for our side etc.
So, just for the slow amongst us...
* I have to import the module in order to see its exported interface (as with any other module)
* I have to include the module to get the compiler to process the implementation code in the submodule.
It's not exactly how I though it worked, but then nothing ever is, it just feels odd that I have to import and include but I am sure there are vey good reasons for it not being automatic i.e. it might remove some flexibility and freedoms somewhere else I guess.
I believe this is the relevant oart of the docs, 9.3.3, Visibility rules:
Declarations in a child module are not visible in the parent module, or in “sibling” modules
(other children of the same parent), or in other unrelated modules unless the child is explicitly
imported using an ‘:- import_module’ or ‘:- use_module’ declaration. It is an error
to import a module without importing all of its parent modules.
Thanks for putting up with me,
I am going to go outside and run my through the mangle for a bit, it hurtsd less.
Sean.
> On 24 Aug 2024, at 14:06, Julien Fischer <jfischer at opturion.com> wrote:
>
> On Sat, 24 Aug 2024 at 22:10, Sean Charles (emacstheviking)
> <objitsu at gmail.com <mailto:objitsu at gmail.com>> wrote:
>>
>> I have a module called `core` in file core.m
>> I have a sub-module called `core.comments` in file core.comments.m
>>
>> :- module core.comments.
>>
>> :- interface.
>> :- import_module io.
>> :- import_module fm.
>>
>> :- pred comment_line(opstate::in, opstate::out, dstk::in, dstk::out, io::di, io::uo) is det.
>> :- pred comment_parens(opstate::in, opstate::out, dstk::in, dstk::out,io::di, io::uo) is det.
>>
>> and my parent module is defined like this:
>>
>> :- module core.
>> :- interface.
>>
>> :- import_module bool.
>> :- import_module io.
>>
>> :- import_module fm.
>> :- import_module vm.
>>
>> :- implementation.
>> :- import_module list.
>> :- import_module string.
>>
>> :- include_module comments. %% <====
>>
>> :- import_module dstack.
>
> You need to import core.comments in the core module as well as include
> it, otherwise what
> core.comments exports won't be visible to it. (What's defined in
> submodules is *not* automatically
> imported into their parents.)
>
> Julien.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20240824/f912cdbb/attachment-0001.html>
More information about the users
mailing list