This goes back some ways but I recently ran into the same issue and once again referred to
http://minnow.cc.gatech.edu/squeak/uploads/SqueakLanguageRef.3.html
on how to create an array literal. When it didn't work again I remembered this old email exchange I had on the subject and it occurred to me that the current language reference does not refer to this (apparently) better array literal formation method.
This is also being CCed to Andrew P. Black, but I'm not sure if he is still the maintainer for this document.
Ken
On Sat, 2002-01-12 at 19:06, Dan Ingalls wrote:
Ken Causey ken@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