chicken-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-hackers] string-append


From: felix winkelmann
Subject: Re: [Chicken-hackers] string-append
Date: Thu, 19 Mar 2009 09:15:16 +0100

On Thu, Mar 19, 2009 at 4:53 AM, Jim Ursetto <address@hidden> wrote:
> I am curious about the behavior of string-append and substring in the 
> compiler.
>
> (define (foo) (string-append "foo" "bar"))
> (eq? (foo) (foo)) ;=> #t
>
> This is because (string-append "foo" "bar") compiles down to the
> single literal "foobar", while R5RS says (string-append) returns a
> newly allocated copy.  The same is true for (substring "foobar" 0).

Yes, the constant-folding is quite aggressive. I will disable constant
folding of these procedures to follow R5RS.

> I also noticed identical literal strings are not coalesced in the
> compiler.  I was interested to know if this is done to ensure these
> strings are separate mutable copies, or if it was just not worth the
> effort to coalesce them.

The former, as mutating them may cause headaches if the literal
is used in different places.


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]