[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Guile: What's wrong with this?
From: |
Mark H Weaver |
Subject: |
Re: Guile: What's wrong with this? |
Date: |
Thu, 05 Jan 2012 14:02:43 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) |
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
- Re: Guile: What's wrong with this?, (continued)
- Re: Guile: What's wrong with this?, Ian Price, 2012/01/04
- Re: Guile: What's wrong with this?, Bruce Korb, 2012/01/04
- Re: Guile: What's wrong with this?, Andy Wingo, 2012/01/04
- Re: Guile: What's wrong with this?, David Kastrup, 2012/01/04
- Re: Guile: What's wrong with this?, Ian Price, 2012/01/04
- Re: Guile: What's wrong with this?, Bruce Korb, 2012/01/04
- Re: Guile: What's wrong with this?, Mike Gran, 2012/01/04
- Re: Guile: What's wrong with this?, Mark H Weaver, 2012/01/04
- Re: Guile: What's wrong with this?, Bruce Korb, 2012/01/05
- Re: Guile: What's wrong with this?, Mark H Weaver, 2012/01/05
- Re: Guile: What's wrong with this?,
Mark H Weaver <=
- 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, 2012/01/06
- 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