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

Krishnan Purushothaman (Sweet M1 Tips)

Regardless of the specifics of your project, M1 probably won't be too difficult. The important part is to start early, so you can get a handle on how much time it's going to take you to finish the assignment. If you haven't been paying attention in class, it may take a bit longer than you think. While the language has a few quirks, for the most part it is straightforward. Here are some basic things you need to know:


1) Basic syntax is "Object Action." So if you wanted to run a String called "test"'s "Read." action, you'd enter "test Read.".

2) Once you've used the context menus to create a new category for your method, you need to click on that category and start typing stuff. Hit Ctrl-S to save. When you do this, it "creates" the method so you can see it listed in the domain.

3) To set an object's value, use the := operator. To check for equality, use the = operator.

4) Commas are how you concatenate Strings in smalltalk. If myVar := 'test','string'. , myVar would be 'teststring'.


Loops are actually pretty easy in smalltalk.

To implement a while loop, simply use whileTrue.
whileTrue:[code in loop].

There is no specific If/Then functionality. Instead, you'll have to make do with whileTrue: and whileFalse:.

For loops are pretty easy as well, just use the following syntax.
(START) to: (END) by: (HOW MUCH YOU WANT TO INCREMENT) do: [:x(this is the item you're currently looking at, this can be anything) | (your code here) ].

6)You're going to need to store data at some point. Arrays are the fast, but you can't add anything to them. For this reason, we tended to use OrderedCollections and SortedCollections.

Ordered Collection rundown:
Has an integer index. New elements are added to the end, although you can add things to the beginning, before a particular item, or before an index value. Useful methods are:

[OrderedCollection] add:[anObject].(Adds the object to the end of the list.)
[OrderedCollection] size.

[OrderedCollection] at:[Integer Index] put:[an Object].

addFirst:anObject, addLast:anObject, removeFirst, and removeLast all do what you'd expect.

With a SortedCollection, you can add things to your collection all willy nilly, without worrying about the order in which you add them. You can do so without having to worry about whether your array will be in the order you want it to be, thanks to the (you guessed it) sorting capabilities of this class!

The important difference between an OrderedCollection and a SortedCollection is the sortBlock, which is the code that determines how items are ordered in the collection. For example, the statement "myColl := SortedCollection sortBlock:[:a :b| a = b]." makes an ascending-order sorted collection named myColl.

Links to this Page