Replying to myself...

>> "it goes without saying (but I'll say it anyway)":
>>
>>    (define a (string-copy "hello"))
>>    (define b a)
>>    (string-upcase! a)
>>    b
>>
>> *does* yield "HELLO" and not "hello".  Why the inconsistency?
>
> You are proceeding from the assumption that each variable contains its
> own string buffer, when in fact they contain pointers, and (define b a)
> copies only the pointer.  In other words, the code above is like:
>
>   char *a = string_copy ("hello");
>   char *b = a;
>   string_upcase_x (a);
>   return b;

Of course, in Scheme (and C) it is possible to do what you want by
changing string-upcase! (string_upcase_x) from a procedure to a macro,
but as you know, macros in C have significant disadvantages.  Scheme
macros are vastly more powerful and robust, but they also have
significant disadvantages compared with procedures.

Here's how you could do what you want with Scheme macros:

  (define-syntax-rule
    (string-upcase!! x)
    (set! x (string-upcase x)))

      Mark

Reply via email to