Comment 7 for bug 961350

Revision history for this message
Pascal J. Bourguignon (pjb-informatimago) wrote : Re: [Bug 961350] Re: generating symbols without with-standard-io-syntax

Stelian Ionescu <email address hidden> writes:

> On Thu, 2012-03-22 at 23:06 +0000, Pascal J. Bourguignon wrote:
>> On 22/03/2012, at 21:14, Attila Lendvai <email address hidden> wrote:
>>
>> > just to clarify, is it something that should be fixed in alexandria?
>>
>> Depends on the specifications of that function of alexandria. Pehaps
>> they want to make symbols according to *print-case*?
>
> My opinion is that format-symbol shuold respect *print-case* and that
> normalizing the build environment should be done by ASDF: I'll try to
> push the use of with-standard-io-syntax into ASDF itself

I don't agree that normalizing the build environment should be done by
ASDF. More exactly, ASDF could wrap a with-syntax-io-syntax, but
libraries should not count on ASDF to do that, because they may (or
will) be compiled or loaded with other tools, where the environment may
have to be not-standard, to hook in code processing tools (eg. one could
set up a non-standard *readtable* to read and analyse a library).

Also, I was perhaps a little disingenious with alexandria:format-symbol.
It's purpose is to avoid problems with the readtable-case, by specifying
the format string as a symbol that is read with the same readtable as
the arguments. Didn't they think about *print-case*? Perhaps they did
and chosed to honor it as a feature. Perhaps they didn't think about it.

IMO, it would be more in line with the (alleged) purpose of
alexandria:format-symbol to wrap its call to format with
with-standard-io-syntax. (modulo the binding of *package*; in my
libraries, I have a wsiosbp macro:

    (defmacro wsiosbp (&body body)
      (let ((vpack (gensym)))
        `(let ((,vpack *package*))
           (with-standard-io-syntax
             (let ((*package* ,vpack))
               ,@body)))))

).

But my point is that it's a bug in iolib, however the environment is set
and however format-symbol is specified, not to control that the symbols
it makes and use match. (The sources of alexandria:format-symbol are
here to see what it does).

The error is to build a symbol name that may be in any case, and to
expect to read it two lines below with the standard (or active)
readtable-case.

Compare:

cl-user> (eq (alexandria:format-symbol *package* "~@{~A~}" 'make- 'stream '|-1|)
             'make-stream-1)
nil
cl-user> (eq (intern (format nil "~@{~A~}" (string 'make-) (string 'stream) (string '|-2|))
                     *package*)
             'make-stream-2)
t

cl-user> (eq (intern (concatenate 'string (string 'make-) (string 'stream) (string '|-3|))
                     *package*)
             'make-stream-3)
t

alexandria:format-symbol does something like:
  (format nil "~@{~A~}" 'make- 'stream '|-2|).

Notice that with a different readtable-case, format-symbol may or may
not give good results, while the two other forms will always give good
results.

--
__PASCAL Bourguignon__ http://www.informatimago.com/
A bad day in () is better than a good day in {}.