[m-rev.] splitting io.m

Zoltan Somogyi zoltan.somogyi at runbox.com
Mon Aug 17 17:48:39 AEST 2015



On Mon, 17 Aug 2015 17:02:55 +1000, Paul Bone <paul at bone.id.au> wrote:
> On Mon, Aug 17, 2015 at 04:43:55PM +1000, Peter Wang wrote:
> > Hi,
> > 
> > Would there be any opposition to splitting io.m into multiple modules,
> > while maintaining the interface?  Most of the predicates have the
> > exported Mercury predicate wrapping private foreign_procs.  I'm thinking
> > the foreign_procs can be moved into submodules.  The submodules might be
> 
> I've also considered splitting up IO.

As have I. I think everyone who has looked at it has considered it :-(
 
> >     io.error
> >     io.read
> >     io.write
> >     io.seek
> >     io.file_type
> >     io.rename
> >     io.file_time
> >     io.environ
> >     io.system
> >     io.make_temp
> >     ...
> 
> This is more finer-grained than I would have chosen.  Also I was going to
> move all things, not just the foreign code, into the other
> modules/submodules.
> 
> This isn't an objection and I don't think it's that strong of a concern.

As for me, I *would* object to putting the declaration of a
user-facing predicate and its implementation in different files, at least
if it is done on a long-term basis, because it would represent avoidable
coupling between the files. I also don't think you would gain all that much
(in terms of the size of io.m) by it. In many cases, the declaration
is as big as the implementation, because of the comments on it.

We *could* divide up the documented interface of io.m into groups
of related predicates (which io.m already does, sort-of), and decide
to put each group of predicates into a module of its own. These groups
could include

- predicates that read from text files (including putback)
- predicates that read from binary files (ditto, if needed)
- same two groups for writes
- predicates that open/close files
- predicates that implement the old prolog-style see/seen/tell/told
  interface
- predicates that invoke system, environ etc

We could move both the declarations and the implementations
of these predicates into the new modules (which need NOT be
submodules of io.m), and leave a forwarding predicate for each
in io.m, with an obsolete pragma.

We would probably need to move the definitions of the C types
currently in foreign_decl pragmas to the runtime, to allow them
to be accessed from the new modules. 

As a related but separate change, we could immediately move
all the non-publically documented parts of io.m that are exported
for use by other parts of the Mercury system (e.g. the debugger)
to new modules.

It may be useful to have further discussions of this be done live,
over Skype or Hangout.

Zoltan.




More information about the reviews mailing list