guile-devel
[Top][All Lists]
Advanced

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

Re: Guile: What's wrong with this?


From: David Kastrup
Subject: Re: Guile: What's wrong with this?
Date: Fri, 06 Jan 2012 15:11:43 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Mike Gran <address@hidden> writes:

> There is an obvious syntax to construct a string immutable
> object: namely to have it appear as a literal in the source code.
> There thus isn't a need for a constructor function.

Huh?  There are _lots_ of strings which are better computed than spelled
out.

> But there is no constructor for a string mutable that initializes
> it with a string in Guile 2.0.

(string-copy "xxxxx")

> There was in Guile 1.8, where
> you could do (define <var-name> <string-literal>).

No, it wasn't.

guile> (define (x) "xxxxx")
guile> (x)
"xxxxx"
guile> (string-upcase! (x))
"XXXXX"
guile> (x)
"XXXXX"
guile>

As you can see, reevaluating the definition suddenly delivers a changed
result, because we are not talking about modifying a mutable string
initialized with a literal, but about modifying the literal itself.

Whether or not you replace the function body with
(define y "xxxxx") y
instead of just "xxxxx" does not change the result and does not change
what happens.  y does not refer to a string initialized from the
literal, it refers to the literal.  And changing the literal is a really
bad idea.

Just because you do not understand what the code did previously does not
mean that the behavior was well-defined.

-- 
David Kastrup




reply via email to

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