Unformatted text preview:

Smalltalk (and Squeak)Historical perspective:PowerPoint PresentationSlide 4Slide 5Squeak!What is Squeak?What’s legal?Data objects:Slide 10Slide 11ConditionalsIf / ElseIf (continued)Some basic syntaxSome more basic syntaxSlide 17The For LoopFileout / fileinComments and LiteralsPseudo - VariablesMessage ExpressionsUnary messagesBinary MessagesKeyword messagesExample in Squeak WindowsBlock ExpressionsIt’s true us long us it’s not falseInheritanceSlide 30Building an applicationSmalltalk (and Squeak)Aida Dungan andRick ShreveHistorical perspective:Alan Kay developed Smalltalk as part of a complete computer system (language, computer, and programmingenvironment) at the Xerox Palo Alto Research Center(PARC) in the early 1970s. This system included suchcomputing novelties (then) as a mouse and a windowed environment.The first practical release of Smalltalk was Smalltalk-72, in 1972, by Dan Ingalls.There is no official standard for the language, but Smalltalk-80 is the generallyaccepted standard. Squeak is the programming environment we will be workingwith for our Smalltalk uses. From the www.squeak.org website: “Squeak is an open,highly-portable Smalltalk-80 implementation whose virtual machine is writtenentirely in Smalltalk, making it easy to debug, analyze, and change. To achievepractical performance, a translator produces an equivalent C program whoseperformance is comparable to commercial Smalltalks.” More on Squeak in a bit.The lack of practical implementations of Smalltalk used to be an impedance to itsgrowth, but it has a devoted following (there’s definitely a cross-over ofinformation between the Smalltalk developer superset, and the Squeakdeveloper subset) which has ported implementations to just about any operatingsystem you can think of; oh and it’s free.In addition to the unusual emergence circumstance for thislanguage, it was also unique in that object orientation was aprimitive built-in concept.There is only a small core language definition. The main thing youdo when developing projects in Smalltalk is to develop classes as subclassesof other classes, and develop methods within these new classes.So, back to Squeak…It runs bit-identical on many platforms (Windows, Mac, Unix, and others).Squeak!The primary design team is at Disney, but again, it is open-source.What is Squeak?To quote from Dwight Hughes, a frequent contributor to theSqueak mailing list, "How is Squeak important? Squeakextends the fundamental Smalltalk philosophy of completeopenness -- where everything is available to see,understand, modify, and extend for whatever purpose -- toinclude even the VM. It is a genuine, complete, compact,efficient Smalltalk-80 environment (*not* a toy). It is notspecialized for any particular hardware/OS platform. Portingis easy -- you are not fighting entrenched platform/OSdependencies to move to a new system or configuration. Ithas essentially been put into the public domain - greatlybroadening potential interest, and potential applications. Thecore team behind Squeak includes Dan Ingalls, Alan Kay,Ted Kaehler, John Maloney, and Scott Wallace. All of thishas attracted many of the best and most experiencedSmalltalk programmers and implementers in the world."What’s legal?Here is a paraphrase of the license terms:You are allowed to change Squeak, write extensions toSqueak, build an application in Squeak, and include some orall of Squeak with your products. You may distribute all ofthese things along with Squeak, or portions of Squeak, forfree or for money. However, you must distribute these thingsunder a license that protects Apple in the way described inthis license.If you modify any of the methods of class objects (or their relationships) thatcome with Squeak (as opposed to building on top of the classes in the release),you must post the modifications on a web site or otherwise make them availablefor free to others, just as has been done with Squeak. The same is true if youport Squeak to another machine or operating system - you must post your porton a web site or otherwise make it available for free to others under the samelicense terms.Data objects:Classes define types in Smalltalk. Variable naming conventions in Smalltalksuggest that strings of letters of multiple words be used. The first letter should belower-case (upper-case in a global variable), and successive words should beginwith a capital letter: myVariable, anInteger, etc… Strings are enclosed by singlequotes.Smalltalk is an interpreted language, so execution is dynamic; variable types arenot specified.There are no built-in structured data in Smalltalk. Data objects such as arrays,sets, and linked lists are predefined in class definitions, and are created by usingthe new: keyword method for the respective class.Example goes here:User-defined types are handled by the inheritance of methods in classdefinitions.Example:ConditionalsWhileA loop which functions as a while loop from C++ would be implemented in Smalltalkin the following way:i:=0.[(i<5)]whileTrue:[Transcript show: ' Number: '. Transcript show: (i). i:=i+1.].“This code generates the following output:” Number: 0 Number: 1 Number: 2 Number: 3 Number: 4If / Elsea:=5.b:=2.((a+b)<10) "this is the evaluated expression"ifTrue: [Transcript show: 'less than ten'; cr.]ifFalse: [Transcript show: 'greater than or equal to ten'; cr.].“The above code produces the following: “less than tenIf (continued)You can use a single ifTrue or ifElse with a precedingexpression to be evaluated, and a following statement block,or you can use them together, as in the previous example,as long as you only put a period after the last block.Some basic syntaxThere is no need to import libraries.The end of line command is a period.“This is a comment in Smalltalk. Use double quotes.”Variable declarations are done like this: |x y z| “no type specifications for variables.”Some more basic syntaxSmalltalk is interpreted, so there is no compilation procedure.To run your code, select all of the text, left-click, and choose‘do it’ from the menu.Assignment is done either as x_1 or x:=1.Equality is checked with a single x=y (rather than == of C++).Brackets are the block delineators [code goes here]^value is how you signify a return value.Data objects:Classes define types in Smalltalk. Variable naming conventions in Smalltalksuggest that strings of letters of multiple words be used. The first letter should belower-case (upper-case in a global


View Full Document

UNCA CSCI 431 - Smalltalk

Download Smalltalk
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Smalltalk and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Smalltalk 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?