[armedbear-devel] RfC: Renaming LispObject.writeToString() to LispObject.printObject()
Mark Evenson
evenson at panix.com
Fri Jul 15 06:50:26 UTC 2011
On Jul 14, 2011, at 20:42 , Erik Huelsmann wrote:
>
> My idea would be to disambiguate the two functions by making writeToString() a java-side PRINT-OBJECT, renaming it to printObject() and documenting that's what it does. Then, probably, the lisp side function %write-to-string should be renamed to %print-object too. Probably, more adjustments are required throughout the code base, but those are probably at the 'implementation detail' level.
I think that the meaning of writeToString() was that the function
should provide an implementation of serialization to a string able
to be READ with the #S notation. It is not really performing a
PRINT-OBJECT-alike function which is a specialization of such an
implementation on Lisp STANDARD-OBJECT or STRUCTURE-OBJECT.
On the other hand there is some justification for not calling such
an implementation writeToString() as that will certainly confuse a
Java user used to every object either inheriting or overrriding
java.lang.Object.toString(). I might suggest then, that to clarify
that this function isn't a direct implementation of CL's PRINT-OBJECT
which actually takes an both arguments to specify the object it is
operating on and to specify the output streamthat we rename the
Java-side to writeLispObject(). The return type of this method,
java.lang.String, makes something more verbose like
writeLispObjectToString() superfluous. I'd leave the Lisp
%write-to-string alone, as the presence of WRITE-TO-STRING in the
CL namespace makes it pretty clear that this is the primitive
implementation. Since %write-to-string has a simple implementation,
looking up its behavior is rather easy.
In any case, I would take advantage of the architecture I started
to define in org.armedbear.lisp.protocol to create an interface
which defines this contract:
package org.armedbear.lisp.protocol;
/** The implementing object can be serialized ala WRITE. */
public interface WriteSerializable { // XXX not crazy about the name here
/** Serialize the implementing object instance in a manner that may be READ via #S */
public String writeLispObject();
}
and then make LispObject implement this interface.
This provides a suitable place for encapsulation and documentation,
being the natural place that a Java programmer will go to
figure out what this method should do as it implements the interface.
--
"A screaming comes across the sky. It has happened before, but there is nothing to compare to it now."
More information about the armedbear-devel
mailing list