This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GSOC | Extending Common Lisp support


On Jun 8, 2012, at 4:55 PM, Charles Turner wrote:

Apropos packages, I've made a start adding the standard CL packages to
Namespace's nsTable. However, this doesn't seem very clean because
when it comes to handling the :use stuff, I need to use the method
LispPackage#use(LispPackage, LispPackage). This is commented out in
trunk, but I'm using it now (with a few minor changes).

Consider processing (make-package "COMMON-LISP-USER" :nicknames
'("CL-USER") :use '("COMMON-LISP")). COMMON-LISP is already in the
namespace (new addition), along with KEYWORD, so to process this form
seems conceptually straightforward:

Namespace commonlisp_user = valueOf("COMMON-LISP-USER") ; works fine,
add a new namespace is nsTable
Namespace commonlisp = valueOf("COMMON-LISP") ; works fine, get the
Namespace for COMMON-LISP which already exists
for each nickname, nsTable.put(nickname, commonlisp_user) ; works fine!
for each use
LispPackage#use(commonlisp_user, use) ; !! #use wants LispPackages,
not Namespaces!


Unless I'm being spectacularly dumb with Java this evening, it seems
like I need a new hash table and associated valueOf method in
LispPackage to accommodate this sort of case. I have a horrible
feeling I'm overlooking something trivial, but I've spent too long
already thinking what the best approach is that I thought it best to
ask!

You don't necessarily need a new hash table: Namespace.nsTable has protected access, so LispPackage, as a subclass, can touch it if needed.

It does look like you need a LispPackage#valueOf which constructs instances
of LispPackage instead of Namespace.. OR (and I'm not sure whether this is
nice cleverness or devious cleverness) add a method like this to Namespace:


public static Namespace valueOf(String name, Class<? extends Namespace> cls)
{
// pretty much the same as the existing valueOf(String),
// but change "ns = new Namespace();"
// into "ns = cls.newInstance();" <-- requires a try/catch around it
}

and you could then change the existing valueOf(String) to


public static Namespace valueOf(String name)
{
  return valueOf(name, Namespace.class);
}

and in your example do
Namespace commonlisp_user = valueOf("COMMON-LISP- USER",LispPackage.class);


That or just add a static valueOf method to LispPackage, which again is
mostly the same as Namespace#valueOf(String) but with
ns = new LispPackage();
...
Namespace.nsTable.put(name,ns)
(Don't forget to put it in a synchronized(Namespace.nsTable) block!)

One wrinkle is that nsTable will have some entries which are LispPackages and
some which are plain Namespaces, so you'll need to do something like


for each use
  if (use instanceof LispPackage)
    LispPackage#use((LispPackage)user,(LispPackage)use);
  else
    ???

If nsTable gives us a Namespace which isn't a LispPackage, what should we do?
Does it ever make sense to :use a Namespace which isn't a LispPackage?


--
Jamison Hope
The PTR Group
www.theptrgroup.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]