Re: term_expansion/2 with DCG clauses

Michael Hendricks <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAFHuXuZa4DBmQp39darJoU5_NWjtrJ7HpjCO7KaeO0rAzHajBA@mail.gmail.com>
Hi Paulo,

On Thu, Aug 15, 2013 at 11:04 AM, Paulo Moura <[email protected]> wrote:

> Another ugly aspect is that now the expansions are no longer independent
> and must know about each other. Even worse if some of the extensions are
> third-party.
>

Yes, "export macros by default" gives us a sad outcome.  Under recursive
expansion, macros lose independence when we need to impose a specific
expansion order.  Under first-solution expansion, we get the same problem
under other conditions (like end_of_file in your chr example).


> > A thought that's only tangentially related: The multifile directive
> acknowledges that clauses are a meaningful unit of code reuse.
>  Unfortunately, multifile creates a single global predicate.  It might be
> helpful if modules could export their clauses to augment an existing, local
> predicate definition.
>
> Not sure I follow. You can declare multifile predicates from your own
> module, besides system ones like "prolog", "user", or "system". This makes
> the predicates local to the module containing the primary multifile
> directive, even if the their clauses are spread (in another modules). Or
> maybe you mean something different when you write about global versus local?
>

Yeah, I didn't explain myself very well and my terminology was confusing.
 Let me try a different approach:

multifile predicates are kind of like an open house party.  Mom and Dad are
out of town, so you buy some Kool-Aid and post on Facebook, "Party at my
house this weekend"  You don't know who will show up, when they'll arrive
or what they might leave in the fridge when they're done.  Sometimes we
want predicates that are more like a country club dinner.  We hand out a
few invitations to some quiet, respectable participants.  They arrive on
time and clean up after themselves.

When the system module declares term_expansion/2 as multifile, the
predicate is local to the system module but that module has no control over
what clauses implement the predicate.  What if we had a directive called
invite_only (to make something up) which allowed one to import clauses.
 For example,

    :- module(mine, []).
    :- invite_only term_expansion/2.
    % import term_expansion/2 clauses from modules a, b and c
    :- use_module(a, [term_expansion/2]).
    :- use_module(b, [term_expansion/2]).
    :- use_module(c, [term_expansion/2]).
    ...

At this point, mine:term_expansion/2 would contain clauses from all three
modules.

multifile is "others push clauses into my predicate" and invite_only is "I
pull clauses into my predicate".

-- 
Michael
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.