Adding a newline to an Array
Jim Benson
jb at speed.net
Sun Nov 16 17:52:42 UTC 2003
Hi Danie,
The #( ... ) element is used for constructing an array of literals or
reserved identifiers, compiles the elements statically. See
http://minnow.cc.gatech.edu/squeak/3435.
Short English translation, you can put things like strings, numbers, symbols
and stuff like that into an array using the #( ... ) construct. This does
*not* include variables. In your example, you can't put the lf into this
array constructor because it's a variable.
You are trying to build an array with a variable included. There are a
couple of ways to build your array:
lf := Character lf.
newArray := Array with: $a with: $b with: lf.
will give you an array with a lf character on the end. Another 'special'
way to build arrays is to use the { ... } construct. In your example:
lf := Character lf.
newArray := { $a. $b. lf }
or
newArray := { $a. $b. Character lf }
(Notice the period after each entry). Conceptually, this evaluates each of
the array entries before actually shoving them into the array.
Hope this helps,
Jim
----- Original Message -----
From: "Danie Roux" <droux at tuks.co.za>
To: "The general-purpose Squeak developers list"
<squeak-dev at lists.squeakfoundation.org>
Sent: Sunday, November 16, 2003 9:14 AM
Subject: Adding a newline to an Array
> Hi,
>
> Bit green to Smalltalk and having trouble with putting a newline
> character in an array:
>
> #($a $b $c) "would give me an array with the three characters a, b and c
> in it."
>
> lf := Character lf. " Would give me the lf character "
>
> Now how do I put lf in an array?
>
> #($a $b #lf) " Doesn't seem to work?"
>
> --
> Danie Roux *shuffle* Adore Unix
>
>
>
More information about the Squeak-dev
mailing list
|