Streams  Allows the traversal of a collection  Associated with a collection —If the collection is a Smalltalk collection: InternalStream —If the collection.

Slides:



Advertisements
Similar presentations
Why not just use Arrays? Java ArrayLists.
Advertisements

Hold data and provide access to it. Random-access containers: -Allow accessing any element by index -arrays, vectors Sequential containers: -Allow accessing.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Stack & Queues COP 3502.
From Objects to Actors Study of a Limited Symbiosis in Smalltalk-80.
CS Data Structures II Review COSC 2006 April 14, 2017
Principles of Object-Oriented Software Development The language Smalltalk.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
Stéphane Ducasse9.1 Inheritance Semantics and Lookup.
Stéphane Ducasse8.1 Syntax and Messages The syntax of Smalltalk is simple and uniform, but it can look strange at first sight! Literals: numbers, 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.
PZ06BX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ06BX - Introduction to Smalltalk Programming Language.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
Some Basic Points on Classes
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Stéphane Ducasse 1 Syntax and Messages.
CHAPTER 6 Stacks Array Implementation. 2 Stacks A stack is a linear collection whose elements are added and removed from one end The last element to be.
Stack: Linked List Implementation Push and pop at the head of the list New nodes should be inserted at the front of the list, so that they become the top.
Squeak Collections The Squeak collection hierarchy. Some collection operators. Working with collections. For-loops.
The List Interface Cmput Lecture 14 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture is based.
3. Standard Classes. © Oscar Nierstrasz ST — Standard Classes 3.2 Roadmap  Object  Numbers, Characters, Strings and Arrays  Variables  Blocks and.
3. Standard Classes. Birds-eye view © Oscar Nierstrasz ST — Introduction 1.2 Reify everything — by reifying its entire implementation model, Smalltalk.
Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.
Stéphane Ducasse 1 Smalltalk in a Nutshell.
Stéphane Ducasse4.1 A Taste of Smalltalk Two examples: –‘hello world’ –A Tomagoshi To give you an idea of: –the syntax –the elementary objects and classes.
Stéphane Ducasse«ChapterNr».1 Basic Objects, Conditionals and Loops Booleans Basic Loops Overview of the Collection hierarchy— more than 80 classes: (Bag,
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
CSE 373 Data Structures and Algorithms Lecture 2: Queues.
Handling Lists F. Duveau 16/12/11 Chapter 9.2. Objectives of the session: Tools: Everything will be done with the Python interpreter in the Terminal Learning.
S.Ducasse Stéphane Ducasse 1 Smalltalk Coding Idioms.
3E-1 Collections in Squeak What are they? Kinds of collections. Basic Operations. Usage of Inheritance in the Collections Library. Roman numbers example.
Chapter 10: Structures and Sequential Access Files
Chapter Ten Structures and Sequential Access Files Programming with Microsoft Visual Basic th Edition.
Centralized vs. Decentralized Interpreter Pattern Visitor Pattern.
Vectors and Grids Eric Roberts CS 106B April 8, 2009.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
File Input and Output (I/O) Engineering 1D04, Teaching Session 7.
Object-oriented programming and design 1 Object Identity = vs. == copying objects Value Object ValueWithHistory.
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
Smalltalk in a.NET World How to write a Smalltalk compiler without writing a VM John Brant
S.Ducasse Stéphane Ducasse 1 Common Mistakes and Debugging in VW.
1 Data Organization Example 1: Heap storage management –Keep track of free chunks of memory Example 2: A simple text editor –Maintain a sequence of lines.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Ten Structures and Sequential Access Files.
CSE 373: Data Structures and Algorithms Lecture 2: Queues.
1 Chapter 13-2 Applied Arrays: Lists and Strings Dale/Weems.
1 Advanced Object Oriented Systems (CM0318) Lecture 8 (Last updated 15th February 2002)
3. Standard Classes. © Oscar Nierstrasz ST — Standard Classes 3.2 Roadmap  Object  Numbers, Characters, Strings and Arrays  Variables  Blocks and.
Stéphane Ducasse 1 Some Points on Classes.
S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.
Stéphane Ducasse 1 A Little Journey in the Smalltalk Syntax.
Stéphane Ducasse 1 Elements of Design - Unit of Reuse.
CSE 373 Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks; Eclipse.
File I/O. Files allow permanent storage of programs and data. ifstream and ofstream objects –For file I/O the inclusion of is required. –Objects for file.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
S.Ducasse Stéphane Ducasse 1 Some Advanced Points on Classes.
Patterns Protect from Change Rule: if something is going to change, make it an object. Strategy: make algorithm an object so it can change State: make.
S.Ducasse 1 Instance Initialization How to ensure that an instance is well initialized? Automatic initialize Lazy initialization Proposing the right interface.
CMSC202 Computer Science II for Majors Lecture 12 – Linked Lists
CSE 373: Data Structures and Algorithms
Stacks and Queues.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Feedback from Assignment 1
Chapter 2 Squeak: Object-oriented design with multimedia applications
CS 331 Principles of Programming Languages
Case Study: Prototyping a Play-Writing Workbench
Introduction to Smalltalk
Smalltalk on a Dime.
Presentation transcript:

Streams  Allows the traversal of a collection  Associated with a collection —If the collection is a Smalltalk collection: InternalStream —If the collection is a file or an object that behaves like a collection: ExternalStream  Stores the current position  Stream (abstract)  PeekableStream (abstract) PositionableStream (abstract) ExternalStream ExternalReadStream ExternalReadAppendStream ExternalReadWriteStream ExternalWriteStream InternalStream ReadStream  WriteStream ReadWriteStream

Example  |st| st := ReadWriteStream on: (Array new: 6). st nextPut: 1. st nextPutAll: ( ). st contents. PrIt-> ( ) st reset. st next. -> 1 st position: 3. st next. -> 2 st := ( ) readStream. st next. -> 1

printString, printOn:  Object>>printString "Answer a String whose characters are a description of the receiver." | aStream | aStream := WriteStream on: (String new: 16). self printOn: aStream. ^aStream contents Node>>printOn: aStream super printOn: aStream. aStream nextPutAll: ' with name:'; print: self name. self hasNextNode ifTrue: [ aStream nextPutAll: ' and next node:'; print: self nextNode name]

Stream Classes  Stream next returns the next element next: n returns the n next elements contents returns all the elements nextPut: anElement inserts anElement at the next position nextPutAll: aCollection inserts the collection element from the next position atEnd returns true if at the end of the collection

Stream Classes (ii)  PeekableStream: Access to the current without passing to the next peek skipFor: anArgument skip: n increases the position of n skipUpTo: anElement increases the position after anElement on: aCollection, creates a stream on: aCol from: firstIndex to: lastIndex (index elements included)

Stream Classes (iii)  PositionableStream skipToAll: throughAll: upToAll: position position: anInteger reset setToEnd isEmpty  InternalStream size returns the size of the internal collection  Creation: method with: (without reinitializing the stream)

Stream Tricks  Transcript is a TextCollector that has aStream TextCollector>>show: aString self nextPutAll: aString. self endEntry  endEntry via dependencies asks for refreshing the window. If you want to speed up a slow trace, use nextPutAll: + endEntry instead of show: |st sc| st := ReadStream on: ‘we are the champions’. sc := Scanner new on: st. [st atEnd] whileFalse: [ Transcript nextPutAll: sc scanToken, ‘ * ‘]. Transcript endEntry

Streams, Blocks, and Files  How to ensure that the open files are closed — MyClass>>readFile: aFilename |readStream| readStream := aFilename readStream. [[readStream atEnd] whileFalse: [....]] valueNowOrOnUnwindDo: [readStream close]  How to find open files (VW specific) (ExternalStream classPool at: OpenStreams) copy inspect

Streams, Blocks, and Files (ii)  Filename appendStream (addition + creation if file doesnot exists) newReadAppendStream, newReadWriteStream (if receiver exists, contents removed) readAppendStream, readWriteStream, readStream, writeStream  Example: Removing Smalltalk comments from a file |inStream outStream | inStream := (Filename named: ‘/home/ducasse/test.st’) readStream. outStream := (Filename named: ‘/home/ducasse/testout.st’) writeStream. “(or ‘/home/ducasse/ducasse’ asFilename)” [inStream atEnd] whileFalse: — [outStream nextPutAll: (inStream upTo: $”). inStream skipTo: $”]. ^outStream contents “do not forget to close the files too”