[Top][All Lists]
[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
- Re: Guile: What's wrong with this?, (continued)
- Re: Guile: What's wrong with this?, David Kastrup, 2012/01/05
- Re: Guile: What's wrong with this?, Mark H Weaver, 2012/01/05
- Re: Guile: What's wrong with this?, Mike Gran, 2012/01/05
- Re: Guile: What's wrong with this?, Mark H Weaver, 2012/01/05
- Re: Guile: What's wrong with this?, Noah Lavine, 2012/01/05
- Re: Guile: What's wrong with this?, Mike Gran, 2012/01/06
- Re: Guile: What's wrong with this?,
David Kastrup <=
- Re: Guile: What's wrong with this?, Mark H Weaver, 2012/01/06
- Re: Guile: What's wrong with this?, Bruce Korb, 2012/01/06
- Re: Guile: What's wrong with this?, David Kastrup, 2012/01/06
- Re: Guile: What's wrong with this?, Mark H Weaver, 2012/01/06
- Re: Guile: What's wrong with this?, Mark H Weaver, 2012/01/07
- Re: mutable interfaces - was: Guile: What's wrong with this?, Bruce Korb, 2012/01/07
- Re: mutable interfaces - was: Guile: What's wrong with this?, David Kastrup, 2012/01/07
- Re: mutable interfaces - was: Guile: What's wrong with this?, Mark H Weaver, 2012/01/07
- Re: mutable interfaces - was: Guile: What's wrong with this?, Mark H Weaver, 2012/01/07
- Re: Guile BUG: What's wrong with this?, Bruce Korb, 2012/01/06