From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.devel Subject: Re: Guile: What's wrong with this? Date: Thu, 05 Jan 2012 14:02:43 -0500 Message-ID: <87sjjuc6r0.fsf@netris.org> References: <4F027F35.5020001@gmail.com> <1325603029.22166.YahooMailNeo@web37906.mail.mud.yahoo.com> <4F032C41.3070300@gmail.com> <87mxa4ifux.fsf@gnu.org> <4F038BF4.1070200@gnu.org> <87obujzmmc.fsf@Kagami.home> <4F048972.5040803@gnu.org> <87lipnm8yx.fsf@Kagami.home> <4F04D01D.5050801@gnu.org> <8762grf28k.fsf@netris.org> <4F05DC47.1000202@gnu.org> <871urednlh.fsf@netris.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1325790195 21310 80.91.229.12 (5 Jan 2012 19:03:15 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 5 Jan 2012 19:03:15 +0000 (UTC) Cc: guile-devel@gnu.org To: Bruce Korb Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Jan 05 20:03:11 2012 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Risak-0001zl-FU for guile-devel@m.gmane.org; Thu, 05 Jan 2012 20:03:10 +0100 Original-Received: from localhost ([::1]:34794 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Risak-0001g0-09 for guile-devel@m.gmane.org; Thu, 05 Jan 2012 14:03:10 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:42578) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Risag-0001fk-Vv for guile-devel@gnu.org; Thu, 05 Jan 2012 14:03:07 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Risac-0001Dc-PZ for guile-devel@gnu.org; Thu, 05 Jan 2012 14:03:06 -0500 Original-Received: from world.peace.net ([96.39.62.75]:57987) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Risac-0001DN-Lb; Thu, 05 Jan 2012 14:03:02 -0500 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=yeeloong) by world.peace.net with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1RisaX-0006Ej-Kg; Thu, 05 Jan 2012 14:02:57 -0500 In-Reply-To: <871urednlh.fsf@netris.org> (Mark H. Weaver's message of "Thu, 05 Jan 2012 13:13:30 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 96.39.62.75 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:13328 Archived-At: 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