Re: Packages
- Posted by Matt Lewis <matthewwalkerlewis at gm?il.c?m> Aug 09, 2007
- 520 views
Derek Parnell wrote: > > I believe Chris has an exagerated sense of this issue too. It is not a problem > in the sense that people are tripping up on it all the time and are thus being > frustrated by the language design. > > This strikes me as a concept that Chris would like to see implemented because > its a neat one. And I agree with that. The concept of "packages" for Euphoria > is a nice one, but the lack of it is not, as we speak, causing any general > angst. > > I think that if I were to advocate such a concept, I'd do only two things: > (1) Create a new keyword that defines the scope of an identifier as being > limited > to the package. This would work like 'global' but things outside the package > could not access the identifier. > eg. > sequence mVersion = "1.0" -- seen only in containing file > package integer vNextID -- seen only in containing package > global constant Foo = "FOO" -- seen only in containing application This seems sane to me. > (2) Define the term package as meaning "all the files in the same directory". > > Thus statements in C:\foo\abc.e can access 'package' items in c:\foo\def.e but > statements in C:\bar\qwerty.e cannot see those 'package' items. I like this less. Along with CChris' reservations, I think that this would complicate the distribution process. This system reminds me of java (not the same, obviously, but some real parallels). Libraries that used the package functionality would have to be kept in their directory structure when distributed [as source] with applications. It's not necessarily a bad thing, but I believe that it's different than how most people currently use libraries. Easier might be to use some kind of a "with package xyz" sort of statement. Package names would have to be treated like normal symbol names for resolution purposes, or we end up in the same mess all over again. To demonstrate this, suppose that both two math libraries used the same package:
with package math
Clearly, neither wants to see the other's packaged symbols. Also, the app using these libs might want to see the packaged symbols of one, but not the other:
-- derek_math.e with package math -- matt_math.e with package math -- my_app.ex include derek_math.e as dmath include matt_math.e as mmath with package dmath:math
The "with package" may not be correct, since it's probably important to declare whether you're extending the package or just using it. Or maybe not. Also, what if you use multiple "with package" statements? Can code be part of multiple packages? What if a symbol is declared as package, but there's no "with package" directive? Are only things surrounded by with/without package included in the package? No doubt there are more questions that need to be answered. Matt