Array literals have changed?

Dan Ingalls Dan at SqueakLand.org
Sun Jan 13 01:06:49 UTC 2002


Ken Causey <ken at ineffable.com>  wrote...

>OK, I'm beginning to think that I'm missing the obvious.  As mentioned
>in a previous email I'm working through Guzdial's _Squeak OODMA_ and to
>be more specific I'm working on Exercise 8 of Chapter 2 on page 47.  I'm
>asked to implement a method switchOn that can be used like
>
>#( ('a' [Transcript show: 'An a was input'])
>   ('b' [Transcript show: 'A b was input']) )
>   switchOn 'a'.
>
>I believe that the Array literal above should result in an Array of 2
>elements, each element being an Array of 2 elements (a String and a
>BlockContext).  But...  What I end up with is an Array of 2 elements,
>each element being an Array of 6 (yes six) elements.  To be most
>specific when I inspect element 1 of the outer Array I get an array
>composed of
>
>1: 'a'
>2: #[
>3: #Transcript
>4: #show:
>5: 'An a was input'
>6: #]
>
>Is this correct behaviour?

Yes.  Blocks have never been recognized within literal arrays in Squeak.

If you want something that looks like this, and that works, use curly braces instead of parentheses.

{ {'a'. [Transcript show: 'An a was input']}.
  {'b'. [Transcript show: 'A b was input']} }
   switchOn 'a'.

The {} construct expects a series of expressions (which can be blocks or anything) separated by '.'.

If you really want to execute the three lines as you gave them, then you'll have to write a recognizer for brackets, and separately ask the compiler to evaluate what comes between them.  That was probably not the intention of the exercise.

Hope this helps

	- Dan




More information about the Squeak-dev mailing list