Squeak and Botkit-Port Jeff Forbes Joel Miller
Introduction ● Squeak is a pure OO language ● Based off of SmallTalk-80 – Designed at Xerox PARC by Alan Kay, Dan Ingalls, Ted Kaehler, and Adele Goldberg – The designers wanted a pure object-oriented, interpreted, easy to use language. – Failed/Abandoned because of the slowness of interpreted languages based on the current technology
Squeak ● Squeak can be obtained at no cost at ● Squeak is self contained and also includes a VM/UI of which all programs are run: – Everything is self contained in an *.image file ● Available for most OSes
The Squeak UI/VM
Squeak Features ● Completely Object Oriented –This means everything is an object! Call by name All code is a message which is sent to an object – An object is an instance of a class – Similar rules to Java ● Garbage collection is standard!
Objects ● Everything is an object ● There are no primitive types ● Even classes are objects!! ● Everything inherits from the Object class ● No dual inheritance, no interfaces ● self is this and super is super
Messages ● 3 Types of Messages: – Unary Ex. ‘abc’ reversed. –Binary ● – Keyword Ex. Transcript show: 5. There can be many keyword messages passed to an object
Syntax ● Assignment x := 13 –In Squeak, the underscore “_” can be used ( ) Arrays: #( ) Character: $e Strings in single quotes Comments in double quotes Equals? = Identity test == Lines are completed with a period # prevents evaluation New creates objects
Order of Operations ● The math inside SmallTalk/Squeak is infinite precision ● Everything left to right – This means * 9 gets evaluated as 63! – 2+(5*9) will get desired result. Messages: Unary > Binary > Keyword
BlockContexts ● Informally called “blocks” ● Used for nearly all structured programming constructs ● Made by putting square brackets around code ● Very similar to lambdas in Scheme
Blocks (cont.) ● [6 + 7] is a block but won't evaluate until you say [6 + 7] value. ● Blocks can have local variables – block := [ :a :b | a + b ] – This would be called as block value: 6 value: 7 ● Blocks introduce pluggability to a class
Conditionals ● The basic conditionals are included: – ifTrue – ifFalse Ex: (x < 15) ifTrue: [ Transcript show: 'less than 15'.] ifFalse: [ Transcript show: 'gt or eq 15'.]
Loops ● whileTrue: – The condition must be a block so it can be re-evaluated ● timesRepeat: – No access to the loop index ● to: do: – First parameter in execute block gets set to index Ex: [x < 15] whileTrue: [ Transcript cr. Transcript show: y. temp := y + z. y := z. z := temp. x := x + 1. ]
BotKit-Port ● BotKit port written by John Purcell ● Written as a masters thesis –Therefore poorly documented ● Directly interfaces with the RCX ● Allows immediate mode and “scripted mode” ● Bug: if statements do not work while sending from the BotKit! (immediate)
Code Examples "simple program which goes foward until communication stops" "From ISpirit initialize. bug := BugBot new. rcx := bug rcx. bug forward. rcx spirit free. "Turn around message: ex. bug turnaround." self rcx soundTrillUp. self forward. self turnLeft; sleep: 200. self backward; sleep: 300. self rcx soundTrillDown.
Examples Cont. "go forward until hit a wall, then backward" ISpirit initialize. bug := BugBot new. rcx := bug rcx. "motor hooked up to port 1 on RCX" theMotor := rcx motor: 1. theMotor on. theSensor := rcx touchSensor: 1. [ theSensor ] whileFalse:[ theMotor forward. ] theMotor backward.
Resources ● Squeak: ● Squeakwiki: ● Squeak: Open Personal Computing and Multimedia by Guzdial and Rose ● BotKit-Port: ● BotKit: arts.com/Bower/Bot-Kit/ (Link Down) Questions?