Now that 0.49 has left the dock (great job Ross and Robert!) here is a
more global issue that may be worth thinking about. I haven't seen any
discussion along these lines yet, but maybe I missed it -- if so,
never mind.
One of the weaknesses of S for building larger packages that can be
used together is the lack of any namespace management facility.
Newer languages like Java, Dylan, Perl, Python, Fortran 90, etc., all
provide some variant of a module system with control over what gets
exported from and imported to modules. I believe something of that
flavor would be very useful in R (or any system). Lots of variations
are possible -- SML probably has the fanciest system of any I know,
Common Lisp's packages are arguably at the other end. An outline of
what might be needed:
For module writers
specify scope of module (part of file, all of file,
several files?)
specify exports, i.e. things that are to be (easily)
accessible when the module is used.
For module users
simple importing (all exported things from a module)
selective importing (just bring in some exported things)
importing with renaming (to avoid conflicts)?
maybe introspection tools to dig out private things in
a module (mainly for debugging -- maybe this should not
be supported).
With R's lexical scoping the ability to implement a module system
exists, e.g a module could be created as
mymodule <- (function() {
import(other.module)
f<-function() { .... }
g<-function() { .... f() .... }
list(h=g)
})()
which is supposed to export g under the name h but hides f.
An import function could do something like
import<-function(module) {
assign values to names in caller's frame
}
Lots of scheme module systems use closures for module systems more or
less along these lines. It would be nice to have some nicer syntax, like
mymodule <- module (other.module) {
...
export(...)
}
or whatever seems most natural (also depends on whether you want to
allow several modules per file, several files per module, or thether
modules have anything to do with files at all).
Making S code into an R module would (aside from dealing with
whatever incompatibilities there might be) just involve adding the
module wrapper and deciding what to export.
If being able to maintain common S and R sources seems important, modules
could be specified with a comment convention as in PostScript, emacs
mode lines, etc., something like
#@&^!R-MODULE mymodule
#@&^!R-IMPORT other.module
....
#@&^!R-EXPORT h=f, k, ...
The provide/require functions do a different but related job and would
need to be considered as part of such a design.
Just some food for thought.
luke
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To:
r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-