Andy Wingo <wi...@pobox.com> writes:

>> David Kastrup <d...@gnu.org> writes:
>>> What for?  It would mean that a literal would not be eq? to itself, a
>>> nightmare for memoization purposes.
>>
>> I agree that it should not be the default behavior, but I don't see the
>> harm in allowing users to compile their own code this way.
>
> Well, we can fix this too: we can make
>
>   "foo"
>
> transform to
>
>   (copy-once UNIQUE-GENSYM str)
>
> with
>
> (define (copy-once key str)
>   (or (hashq-ref mutable-string-literals key)
>       (let ((value (string-copy str)))
>         (hashq-set! mutable-string-literals key value)
>         value)))

Although this is a closer emulation of the previous (broken) behavior,
IMHO this would be less desirable than simply doing (string-copy "foo")
on every evaluation of "foo", which seems to be what Bruce (and probably
others) expected "foo" to do.

For example, based on the mental model that Bruce apparently had when he
wrote his code, he might have written something like this:

  (define (hello-world-with-one-char-changed i c)
    (define str "Hello world")
    (string-set! str i c)
    str)

Your UNIQUE-GENSYM hack emulates the previous behavior that makes the
above procedure buggy.  Simply changing "hello" to (string-copy "hello")
would make the procedure work, and I believe conforms better to what
Bruce expects.

Of course, I'm only talking about what I think should be done when the
compiler option is changed to non-default behavior.  I strongly believe
that the _default_ behavior should stay as it is now.

      Mark

Reply via email to