Re: Re: hierarchical packaging (was: Java API)

Leon Bottou <[email protected]> Mon, 13 Feb 2006 17:10:54 -0500
Newsgroups gmane.lisp.lush.devel
Message-ID <[email protected]>
On Monday 13 February 2006 17:01, Ralf Juengling wrote:
> On Mon, 13 Feb 2006, Raymond Martin wrote:
> >
> > To be able to load specific functions from file could be good in Lush, but I cannot
> > see an overwhelming need to implement it. The use of an import statement is
> 
> I hoped my '(defmacro print arg '()) was a somewhat sensible example
> for why you want to do that. Using Python I have grown accustomed to
> defining all sorts of helper functions with short names that I don't
> want to use outside the scope of a module. In Lush I must be much
> more careful because I cannot avoid importing helper functions and
> occasionally run into weird errors because of name clashes.

Yes this is a problem.

See the (package ... ) construct for an imperfect workaround.


------------------------------------------------------------------------
(package <name> <..expressions..>)            [DM](sysenv.lsh)
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Author(s):  Leon Bottou

This construct provides a simple way to make symbols "semi-private" to a
group of functions so as to avoid name clashes. It basically has the
effect of prepending the package name to all the symbols defined within
its scope and marked as private (using the private construct).

Example:
   (package foobar
      (private foo)
      (de foo(x) (print x))
      (de bar(x) (foo x)) )

defines a global symbol bar . Symbol foo however is renamed foobar.foo
in all expressions occuring after (private foo) . Hence the above
expression would be equivalent to:
  (de bar (x)
    (toto.foo x) )
  (de toto.foo (x)
    (print x) )

Internals: Symbol name is used to identify the group of functions.
Function package maintains a list of hidden symbols declared with
function private . Each expression is first transformed to replace all
occurences of a hidden symbol by a new symbol whose name is composed by
prepending the package name name , then evaluated as usual.



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642