Re: Packages

new topic     » goto parent     » topic index » view thread      » older message » newer message

Pete Lomax wrote:
> 
> <aside>
> A point that should be made here, or rather just stating the obvious:
> As things stand, machine.e does not have any package definitions, so if it
> happens
> to be included as part of win32lib, in no way does it mean that anything
> global
> in it will suddenly become invisible to any program that includes win32lib
> with
> some new whizz-bang package system.
> </aside>

> <aside continued>
> And myap.exw could still see machine.e globals even if it does not.
> </aside>

Yes, it was an incredibly poor example.

> If it were up to me, I'd probably go with "package <name>" as the scope
> opener to allow explictly naming the scope that is being shared/not open a new
> one if that name is already active, and "private integer/function".
> 
> As an example for nesting, suppose dll.e wants to privately share a coupla
> things
> with machine.e (as unlikely as that may actually be):
> 
> }}}
<eucode>
> -- win32lib.ew
> package win32lib
> private r_DoStuff
> include dll.e
>    -- dll.e
>    package dllmach
>    private x,y
>    include machine.e
>        -- machine.e
>        package dllmach
>        private p,q
>        <eof>
>    <eof>
> include w32file.e
> <eof>
> </eucode>
{{{

> 
> The proposal I make is that "package <name>" opens a new "scope" which covers
> sub-includes and automatically closes at eof.
> 
> Hence in the above, dll.e and machine.e can see x,y,p,q but win32lib cannot,
> and win32lib and w32file can see r_DoStuff but anything that includes win32lib
> cannot. Further w32file need not have any package statement unless it wants
> to be explicit about it.

My concern with this is that everyone has to choose unique package names,
or libraries with conflicting package names risk leaking into each other.

I like Derek's implementation, but still question whether we need to
name packages.  The only reason I can see would be for diagnostic reporting.
We could use the file name, but what if there are multiple packages in a
single file?
-- gui.e
package memory
    include alloc.e
    include free.e
end package

package gui
    include window.e
    ...
end package

If we decide names aren't required (or maybe even if we do), then the 
following would work:
-- gui.e
with package memory
    include alloc.e
    include free.e
without package

with package gui
    include window.e
    ...
without package

Another advantage of with/without is that we don't introduce another keyword
into the language.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu