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: Fri, 06 Jan 2012 13:13:47 -0500 Message-ID: <877h14bsx0.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> <878vlldb4k.fsf@netris.org> <1325811764.22562.YahooMailNeo@web37903.mail.mud.yahoo.com> <87wr95bo9y.fsf@netris.org> <1325857075.77324.YahooMailNeo@web37903.mail.mud.yahoo.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1325873672 11439 80.91.229.12 (6 Jan 2012 18:14:32 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 6 Jan 2012 18:14:32 +0000 (UTC) Cc: Bruce Korb , guile-devel@gnu.org To: Mike Gran Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Jan 06 19:14:27 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 1RjEJ4-0002NZ-9n for guile-devel@m.gmane.org; Fri, 06 Jan 2012 19:14:22 +0100 Original-Received: from localhost ([::1]:55757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjEJ3-0003cj-GB for guile-devel@m.gmane.org; Fri, 06 Jan 2012 13:14:21 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:44780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjEJ1-0003cZ-5p for guile-devel@gnu.org; Fri, 06 Jan 2012 13:14:20 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RjEJ0-00068q-0a for guile-devel@gnu.org; Fri, 06 Jan 2012 13:14:19 -0500 Original-Received: from world.peace.net ([96.39.62.75]:38958) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjEIz-00067l-Tb; Fri, 06 Jan 2012 13:14:17 -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 1RjEIj-0001TL-Mb; Fri, 06 Jan 2012 13:14:02 -0500 In-Reply-To: <1325857075.77324.YahooMailNeo@web37903.mail.mud.yahoo.com> (Mike Gran's message of "Fri, 6 Jan 2012 05:37:55 -0800 (PST)") 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:13362 Archived-At: Mike Gran writes: > The word 'string' in Scheme is overloaded to mean both string > immutables=C2=A0and string mutables.=C2=A0=C2=A0 Since a string immutable > can't be modified to be a mutable, they really are different > object types.=C2=A0=C2=A0String mutables appear to still exist in=C2=A0th= e=20 > latest draft of=C2=A0R7RS.=C2=A0 > =C2=A0 > Many of the procedures that operate on strings will are overloaded > to take both immutables and mutables, but some, like string-set! > take only mutables. This is the wrong way to think about it. In Scheme, mutable and immutable strings are _not_ different types. The way to think about it is that in Scheme, the program text itself is immutable, including any literals contained in it. This is true of _all_ literals, including '(literal lists), '#(literal vectors), "literal strings", #'(literal syntax) and any other types that might be added in the future that would otherwise be mutable. Imagine that you were evaluating Scheme by hand on paper. You have your program written on one page, and you have another scratch page used for the data structures that your program creates during evaluation. Suppose your program contains a very large lookup table, written as a literal list. This lookup table is on your program page. Now, suppose you are asked to evaluate (lookup key big-lookup-table). The way Scheme works is that `big-lookup-table' is _not_ copied. As `lookup' traverses the table, it contains pointers within the program page itself. However, Scheme prohibits you from modifying _anything_ that happens to be on the program page. It's not a question of type. It's a question of which page the data happens to be on. Now, we _could_ force you to copy big-lookup-table from the program page onto the scratch page before doing `lookup', just in case `lookup' might try to mutate its structure. But that would be a lot of wasted effort. Alternatively, we could allow you to modify the program itself. This is what Guile 1.8 did. You _could_ make an argument that this is desirable, on the grounds that we should trust that the programmer knows what he's doing. However, it's clear that Bruce did _not_ understood what he was doing. I don't think that he (or you) realized that the following procedure was buggy in Guile 1.8: (define (ten-spaces-with-one-star-at i) (define s " ") (string-set! s i #\*) s) Guile 1.8's permissivity allowed Bruce to unwittingly create a large body of code that was inherently buggy. IMHO, it would have been much better to nip that in the bud and alert him to the fact that he was doing something that was almost certainly unwise. > There is a need for a constructor function to create string mutables, > because a literal string in the source code indicates a string immutable. > =C2=A0 > There are such constructors: (string ...) and (make-string k ) > which is fine. > =C2=A0 > But there is no constructor for a string mutable that initializes > it=C2=A0with a string in Guile 2.0. Yes there is: (string-copy "string-literal") If you don't like the name, then rename it: (define mutable-string string-copy) Mark