Re: Unreadable Objects: current status and where to go
Lassi Kortela 09 Dec 2022 17:53 UTC
> If you stick to #<...> (the original domain of SRFI 243), you can
> really only make one effective constraint, namely the following:
>
> "A Scheme implementation supports SRFI 243 if its standard reader (and
> its read/get-datum procedure(s)) signal an error/raise an exception
> when the token #< is read."
>
> (Everything else is non-normative.) Given this specification, R6RS
> systems would all support SRFI 243 and probably most R7RS systems as
> well.
It might make sense to specify a procedure,
(write-unreadable-object object)
that writes `object` using the customary notation of the Scheme
implementation.
For implementations using #? it would be as simple as:
(define (write-unreadable-object object)
(write-string "#?")
(write object))
For implementations using #< it could be something like:
(define (write-unreadable-object object)
(write-string "#<")
(write (if (or (null? object)
(pair? object))
object
(list object)))
(write-string ">"))
or:
(define (write-unreadable-object object)
(write-string "#<")
(cond ((list? object)
(for-each (lambda (item)
(write-string " ")
(write item))
object))
(else
(write-string " ")
(write object)))
(write-string " >"))
or whatever else preserves the closing ">" as unambiguous.
Given the chaotic situation in the field, it's probably not worthwhile
to attempt to write any readers that skip #<...>, but the above solution
can unify #<...> and #?datum from the Scheme programmer's (and Scheme
_implementation_ programmer's) point of view, and paves the way for
standardizing well-formed unreadable-object syntax in the future.
> If you move to #?, the focus of SRFI 243 seems to change considerably.
> Could you write down the intended normative part in a few sentences of
> such a version of SRFI 243?
Change the RnRS grammar so <compound datum> includes <unreadable>
where <unreadable> == "#?" <datum>
When `(read)` reads <unreadable>, it raises an error (we could specify a
standard subtype of read-error for this purpose, call it e.g.
unreadable-object-error).
and export library procedure (write-unreadable-object object) which
writes that syntax.