On Aug 4, 2009, at 14:07, Tobias C. Rittweiler wrote:
> Nikodemus Siivola <nikodemus@...> writes:
>> While ~ is explicitly reserved, I somehow feel that using sharpmacros
>> is preferable, as they tend to stand out better from source text. #"
>> seems sanish to me -- as long as the code that does the printing
>> checks the readtable before using it.
> How about #T? T for Type. This generalizes nicely. So for example
> #T(simple-base-string "foobar"),
> #T(simple-array fixnum (3) #(1 2 3))
> Or even...
> #THE(simple-base-string "foobar")
This structure, especially in the second case, makes it difficult to
implement because you can't just READ-DELIMITED-LIST (unless you want
to read once and then reconstruct as the specified type). Also, giving
a special interpretation to the last element of the list is *somewhat*
#T((simple-array fixnum (3)) #(1 2 3))
Since the type is not flattened in the list, the occurrence of the
value can be predicted without lookahead, and the read procedure is
(defun read-sharp-t (...)
Read type specifier
Read value with appropriate context
Two concrete definitions, both designed to be usefully user-extensible:
1. #T binds SB-EXT:*READ-COERCE* to the type specifier. The
implementations of ", #(, and #A would check *READ-COERCE* to
determine what type of array to allocate.
2. #T invokes a generic function (sb-ext:read-typed stream type-
Option 1 is simpler, in that the dispatch is handled by whatever read-
macro occurs inside the #T. (To avoid silent maybe-misbehavior, it
would be good for the #T implementation to check that the value is of
the given type.)
Option 2 is more powerful, in that the contained read syntax can be
Both of these could be implemented as compatibility libraries in other
Lisp implementations, though option 1 would require overriding more
syntax, or special peeking cases in the definition of #T.
Option 2 has the useful property that it can be used as a hook for
user-defined read syntax identified by symbol (benefiting from the
package system) rather than by readtable and character; new kinds of
readable object could be introduced without requiring the user to
choose readtables. (Think of it as #S extended beyond structures.)
Kevin Reid <http://switchb.org/kpreid/>