Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!mcnc!unc!steele From: steele@unc.cs.unc.edu (Oliver Steele) Newsgroups: comp.lang.smalltalk Subject: Re: literals Message-ID: <748@unc.cs.unc.edu> Date: Sat, 4-Jul-87 10:35:42 EDT Article-I.D.: unc.748 Posted: Sat Jul 4 10:35:42 1987 Date-Received: Sat, 4-Jul-87 20:05:58 EDT References: <938@argus.UUCP> Reply-To: steele@unc.UUCP (Oliver Steele) Organization: University of North Carolina, Chapel Hill Lines: 65 Keywords: literals methods From steele Sat Jul 4 10:29:54 EDT 1987 In article <938@argus.UUCP> bmc@argus.UUCP (Bob Czech) writes: > > I've been working on a variation of the smalltalk model and in studying >the VM I've found that if you have a string constant in a method and assign it >to an instance variable and somewhere down the line you make a modification to >that string, that the constant in the method would hence change. Is this >correct? And if so, I see it as a major flaw that you would be able to modify >a constant! Except for the term "string _constant_", it is correct. Strings and other arrays (you will get the same behavior if you use #(this is a test) in a method and later 'at: 1 put: #that' it) are not constants in Smalltalk. This behavior is true of most languages that I can think of. Try: TRS-80 Disk BASIC: 10 A$ = "Hi" 20 LSET A$ = "Ho" RUN LIST C on any machine without an MMU: char a[] = "Hi"; main() { a[1] = 'o'; puts(a); } PDP-11 FORTRASH: CHARACTER A(2) DATA A/'H','I'/ A(2) = 'O' TYPE 10, A(1), A(2) 10 FORMAT(2A1) CSI FORTH: : t " Hi" ; 121 t 2+ ! t COUNT PRINT Franz Lisp: (defun a () '(this is a test)) (rplaca (a) 'that) (pp a) It may be confusing, but it seems very much the norm among languages. What you want is 'instance _ 'Hello' copy', or 'stream _ WriteStream on: String new'. Many BASICs do this copy automatically for you in the case of an assignment unless the lvalue is an LSET, RSET, or INSTR, so strings really do act as constants for most purposes in that language except when use an LSET. ------------------------------------------------------------------------------ Oliver Steele ...!{decvax,ihnp4}!mcnc!unc!steele steele%unc@mcnc.org "They're directly beneath us, Moriarty. Release the piano!"