View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Sum2003 Midterm Review: Reading Code

1) It prints out abcdefghi,jkl (no spaces) (Did you mean to have the comma in the array?)

2) It goes through the do loop 4 times, one for each element in the array.

3) It gets printed an infinite amount of times. In order to get it printed out 9 times (what the user probably expects) is to replace [test] with [i < 10] or to change the lines test := (i < 10) to test := [i < 10] and then put test value inside the block before the whileTrue:.


2) it actually goes through the loop 5 times because the , counts as an element.



side note: i personally think that it is a bad design standard to treat 'abc','def' as three separate things in an array while 'abc','def' anywhere else would concatenate the strings together.. is there some other purpose for this?


1. I agree that transcript shows abcdefghi,jkl
2. do: loop got executed 5 times.
3. hello gets printed infinitely.
~Sabina Karkin

I have to say that the comma bothers me. I'd like to hear from a TA on this one... Seems to me that it would concatenate 'ghi' and 'jkl' but i'm not sure...



Ok, I think this would be a really crappy question to have a closed-book test, but maybe I can explain it to you. The #( symbol macro tells the reader to read an array of quoted literals until it encounters a close parenthesis. What that means is that the contents aren't evaluated. It's a similar idea to using (quote a b c) or '(a b c) in scheme. This is covered in section 3.4.6.6 in the ansi smalltalk standard draft revision 1.9. So what you actually have in the array, is a symbol, which is the comma. (anArray at: 4) class "...is Symbol".
So if you have a nested thing like (Transcript show: 'die!'), it will be quoted also with symbols. HTH, timmy



Good answer. I agree that this would be a nasty question to put on the midterm. My questions wouldn't be this tricky. Barbara Ericson




Link to this Page