Smalltalk (and Squeak) Aida Dungan and Rick Shreve.

Slides:



Advertisements
Similar presentations
Lecture 2 Introduction to C Programming
Advertisements

Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
Principles of Object-Oriented Software Development The language Smalltalk.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 4 – Introducing Algorithms, Pseudocode and.
Introduction to Programming with Java, for Beginners Primitive Types Expressions Statements Variables Strings.
Stéphane Ducasse 1 The Taste of Smalltalk.
13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.
CMT Programming Software Applications
PZ06BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06BX - Introduction to Smalltalk Programming Language.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
JavaScript, Fourth Edition
JavaScript, Third Edition
Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.
Introduction to C Programming
Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.
Admin Office hours 2:45-3:15 today due to department meeting if you change addresses during the semester, please unsubscribe the old one from the.
Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
A First Book of ANSI C Fourth Edition
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
CPS120: Introduction to Computer Science Decision Making in Programs.
What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server PHP supports.
Python uses boolean variables to evaluate conditions. The boolean values True and False are returned when an expression is compared or evaluated.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
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.
RUBY by Ryan Chase.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
3C-1 Identifiers Variables Literal Objects  Numbers  Characters  Strings Control Structure  Blocks  Conditionals  Loops Messages Defining New Classes.
By Mr. Muhammad Pervez Akhtar
C++ for Engineers and Scientists Second Edition
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.
2: Basics Basics Programming C# © 2003 DevelopMentor, Inc. 12/1/2003.
Expressions and Order of Operations Operators – There are the standard operators: add, subtract, divide, multiply – Note that * means multiply? (No times.
CSE 3302 Programming Languages Chengkai Li Fall 2007 Smalltalk Lecture 14 – Smalltalk, Fall CSE3302 Programming Languages, UT-Arlington ©Chengkai.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Programming Language C++ Lecture 3. Control Structures  C++ provides control structures that serve to specify what has to be done to perform our program.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Today… Operators, Cont. Operator Precedence Conditional Statement Syntax. Winter 2016CISC101 - Prof. McLeod1.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Information and Computer Sciences University of Hawaii, Manoa
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 6 JavaScript: Introduction to Scripting
Chapter 2: Introduction to C++
MATLAB: Structures and File I/O
C++ for Engineers and Scientists Second Edition
Arrays, For loop While loop Do while loop
Introduction to C++ Programming
WEB PROGRAMMING JavaScript.
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
C Programming Getting started Variables Basic C operators Conditionals
Chapter 2: Introduction to C++.
Chapter 2 Programming Basics.
Introduction to C Programming
CSE 3302 Programming Languages
Class code for pythonroom.com cchsp2cs
Smalltalk on a Dime.
Presentation transcript:

Smalltalk (and Squeak) Aida Dungan and Rick Shreve

Historical perspective:

Squeak! The primary design team is at Disney, but again, it is open-source.

What is Squeak?

What’s legal?

Data objects:

Example goes here:

Example:

Conditionals While A loop which functions as a while loop from C++ would be implemented in Smalltalk in 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: 4

If / Else a:=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 ten

If (continued) You can use a single ifTrue or ifElse with a preceding expression 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 syntax There 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 syntax Smalltalk 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:

The For Loop Similar to Fortran, the Smalltalk For loop is done with a to:by:do: statement. 1 to: 100 by: 20 do: [:x | Transcript show: ‘hello world ‘; cr.] “The above code produces the following: “ hello world

Fileout / filein The way to store your code as a small text file (without the Squeak image) if to create a *.st file using the fileout command. The directions for making the fileout are included in part of the assignment Dr. Bruce has assigned. To read this code into a Squeak image, you must open a file list, and use the filein command. This process is detailed at

Comments and Literals zComments “here is one comment that can span many many lines” zNumbers instances of class Number (Integers, Floats, Fractions) zCharacters (Instances of class Character) character preceded by a dollar sign $x $3 $< $$ zStrings (Instances of class String) ‘sequence of “with comment inside” characters’

Pseudo-variables are reserved identifiers that are similar to keywords in other languages. nil true false are constants. self - the current object, that is, the receiver of the current message; like ( this in C++) super - refers to the same object as self. However, the search for a suitable method starts in the superclass of this class. Pseudo - Variables

Message Expressions zThe association of a method with an object is called a message. zMessage expressions are sequences of messages sent to objects. zExpressions consist of selectors followed by their arguments if any.  Messages names should indicate the type of action desired. zThere are three types of messages: Unary messages: (new abs factorial sqrt asString) Binary messages: (+n -n *n /n \\ -”remainder”) Keyword messages: (6 between: 3 and: 9 - “true”) more on messages  Available :

Unary messages zMessages without arguments. Unary message to a class: ’new’ returns a newly created instance of a class MyFriend zMessages that are most tightly parsed left to right. “same as (((9 sqrt)rounded)asString) 9 sqrt rounded asString |friend| friend := MyFriend new

Binary Messages Used for arithmetic operations Binary messages are always parsed left to right, regardless of the precedence of numeric operations. Use of parentheses is a good idea!!!!!! 3+4 77 3+4*5  factorial  27

Keyword messages Use keywords to name arguments.  stores value in array at index  same, but stores at index factorial Messages can be nested. Parsing order is left to right, precedence is: unary  binary  keyword, use parentheses if necessary. Messages sent to the same receiver may be “cascaded” just use semicolons; array at: 3 put: 12 array at: 3factorial put 12 receiver show; +23; at:23 put: 4

Example in Squeak Windows

Block Expressions zBlock without arguments [expressionSequence] zBlock with arguments and local variables. [ (:identifier)+||identifier+|expressionSequence] block that an argument global message new is an object variable line name 1 to: 5 do: [:I | (Transcript show: ‘Hello friend’) cr]

It’s true us long us it’s not false ifTrue: alternativeBlock ifFalse: alternativeBlock. They can be used separately or together to form if/else block. If used together, put a period after the second block, but not the first.

Inheritance zObject is the root of Smalltalk’s inheritance hierarchy, providing some basic functionality to all objects. zSmalltalk only supports single inheritance, but methods can be passed through multiple levels of parent classes. zIf any method is not defined for an object, the parent of that object is called with the same method.

Inheritance Object Magnitude Number Float Integer Fraction Character Boolean False True

Building an application