[GSoC] Parameter protocols in CL
Per Bothner
per@bothner.com
Sat Jul 21 21:11:00 GMT 2012
On 07/21/2012 01:41 PM, Charles Turner wrote:
> On 19 July 2012 23:56, Per Bothner <per@bothner.com> wrote:
>> So what you need to do is add a method to LispPackage like:
>>
>> public static LispPackage(String uri, SimpleSymbol prefix) { ... }
>>
>> or better, override writeExternal:
>>
>> public void writeExternal(ObjectOutput out) throws IOException
>> {
>> out.writeObject(getName());
>> out.writeObject(prefix);
>> }
>>
>> and then implement:
>>
>> public static LispPackage(String name) { ... }
>>
>> where the ... should be the equivalent of find-package-or-error.
>
> I assume you mean public static LispPackage {make,valueOf}.
Yes.
> I've tried
> both approaches, as well as a constructor approach. All with the
> writeExternal() method as you sent.
I might have been unclear. The key point is that the number and types of
values written by writeExternal has to match the parameter types of
make/valueOf/<init>.
> LispPackage:
> public static ThreadLocation<LispPackage> currentPackage
> = new ThreadLocation<LispPackage>("package");
> static { currentPackage.setGlobal(CLNamespace); }
>
> CommonLisp:
> defAliasStFld("*package*", "gnu.kawa.lispexpr.LispPackage",
> "currentPackage");
Seems right, though perhaps "package" should be "*package*".
> I tried the LList approach of just empty constructor & writeExternal
> method. This worked in that the Literals error went away, so I must be
> misunderstanding something else.
That probably finds the default constructor.
> I tried
>
> public LispPackage(String name) { // do nothing for now }
> public void writeExternal(ObjectOutput out) throws IOException
> {
> out.writeObject(getName());
> out.writeObject(prefix);
> }
>
> As I think you suggested, but that still have the error, as well as
> what I thought was the correct method:
>
> public LispPackage(String name, SimpleSymbol prefix) { // do nothing for now }
> writeExternal as before.
>
> I do have to declare an empty constructor in addition to the ones
> above, because I use it in other places initializing a new package,
> new LispPackage();
>
> And in fact, I implemented a valueOf method in LispPackage some time
> ago, which hasn't seemed to solve the problem either:
>
> public static LispPackage valueOf (String name)
> {
> if (name == null)
> name = "";
> synchronized (nsTable)
> {
> Namespace ns = (Namespace) nsTable.get(name);
> if (ns != null)
> return (LispPackage) ns;
> ns = new LispPackage ();
> ns.setName(name.intern());
> Namespace.nsTable.put(name, ns);
> return (LispPackage) ns;
> }
> }
Looks right to me.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
More information about the Kawa
mailing list