SlideShare a Scribd company logo
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Scala: An OO Surprise 
Apostolos Syropoulos 
Xanthi, Greece 
4th European Lisp Symposium 
March 31st - April 1st, 2011 
TUHH, Hamburg University of Technology, 
Hamburg, Germany 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Outline 
1. Introduction 
What is Scala? 
Object Orientation 
Scalability 
2. Functional Features 
3. Parser Builders 
4. XML Processing 
5. XML Processing 
6. Concurrent Programming
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
A scalable language. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
A scalable language. 
Has features found in functional programming 
languages, but it is not a functional langauge! 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
A scalable language. 
Has features found in functional programming 
languages, but it is not a functional langauge! 
Allows concurrent programing. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
A scalable language. 
Has features found in functional programming 
languages, but it is not a functional langauge! 
Allows concurrent programing. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
A scalable language. 
Has features found in functional programming 
languages, but it is not a functional langauge! 
Allows concurrent programing. 
Includes facilities for GUI programming. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
A scalable language. 
Has features found in functional programming 
languages, but it is not a functional langauge! 
Allows concurrent programing. 
Includes facilities for GUI programming. 
Seamless integration of XML. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
A scalable language. 
Has features found in functional programming 
languages, but it is not a functional langauge! 
Allows concurrent programing. 
Includes facilities for GUI programming. 
Seamless integration of XML. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A versatile programming language 
A purely object-oriented language. 
Runs on the Java Virtual Machine. 
A scalable language. 
Has features found in functional programming 
languages, but it is not a functional langauge! 
Allows concurrent programing. 
Includes facilities for GUI programming. 
Seamless integration of XML. 
Provides parser combinators. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Principles of Object Orientation 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Principles of Object Orientation 
Abstraction (i.e., a software object is an 
idealization of a real world object). 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Principles of Object Orientation 
Abstraction (i.e., a software object is an 
idealization of a real world object). 
Encapsulation (i.e., a data protection 
mechanism). 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Principles of Object Orientation 
Abstraction (i.e., a software object is an 
idealization of a real world object). 
Encapsulation (i.e., a data protection 
mechanism). 
Inheritance (i.e., an object may extend the 
functionality of another object). 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Principles of Object Orientation 
Abstraction (i.e., a software object is an 
idealization of a real world object). 
Encapsulation (i.e., a data protection 
mechanism). 
Inheritance (i.e., an object may extend the 
functionality of another object). 
Polymorphism (i.e., software modules may have 
different instances with identical behavior). 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
What makes a programming language 
scalable? 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
What makes a programming language 
scalable? 
Any language that can be extended seamlessly 
is scalable. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
What makes a programming language 
scalable? 
Any language that can be extended seamlessly 
is scalable. 
Gyu L. Steel Jr.: “[A] language design can no 
longer be a thing. It must be a pattern–a pattern 
for growth–a pattern for growing the pattern for 
defining the patterns that programmers can use 
for their real work and their main goal.” 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
What makes a programming language 
scalable? 
Any language that can be extended seamlessly 
is scalable. 
Gyu L. Steel Jr.: “[A] language design can no 
longer be a thing. It must be a pattern–a pattern 
for growth–a pattern for growing the pattern for 
defining the patterns that programmers can use 
for their real work and their main goal.” 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
What makes a programming language 
scalable? 
Any language that can be extended seamlessly 
is scalable. 
Gyu L. Steel Jr.: “[A] language design can no 
longer be a thing. It must be a pattern–a pattern 
for growth–a pattern for growing the pattern for 
defining the patterns that programmers can use 
for their real work and their main goal.” 
There two forms of growth: variable vocabulary 
or variable semantics. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
What makes a programming language 
scalable? 
Any language that can be extended seamlessly 
is scalable. 
Gyu L. Steel Jr.: “[A] language design can no 
longer be a thing. It must be a pattern–a pattern 
for growth–a pattern for growing the pattern for 
defining the patterns that programmers can use 
for their real work and their main goal.” 
There two forms of growth: variable vocabulary 
or variable semantics. 
Generic types, operator overloading, and 
user-defined light-weight types form the kernel 
of every scalable language. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
A Generic Stack
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
A Generic Stack 
class Stack [γ] (n: Int) { 
private var S = new Array[γ](n) 
private var top = 0; 
def push(elem: γ) { 
top = top + 1 
S(top) = elem 
} 
def pop () : γ = { 
var oldtop = top 
top = top - 1 
S(oldtop) 
} 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
User-Defined Light-Weight Complex 
Numbers 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
User-Defined Light-Weight Complex 
Numbers 
class Complex(val re: Double, val im: Double) { 
def + (x: Complex) = 
new Complex(re + x.re, im + x.im) 
def unary_- = new Complex(-Re, -Im) 
. . . . . . . . . . . . . . . . . . 
override def toString = if(re == 0 && im == 0) "0" … 
} 
object Complex{ 
def apply(re: Double)(im: Double) = 
. . . . . . 
new Complex(re, im) 
} 
object i extends Complex(0.0, 1.0) 
. . . . . . . . . . . . . . . . . . . 
var a = 5 + 3.0*i // a complex number!!!
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Call-By-Name or how to define new 
commands 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Call-By-Name or how to define new 
commands 
def loop(pre: => Unit)(cond: => Boolean) 
(post: => Unit): Unit = { 
. . . . . . 
pre 
if (!cond) { 
post 
loop(pre)(cond)(post) 
} 
else 
() 
} 
var x=6; var y=0 
loop { 
x=x-1; y=y+1 
} (x == 0 ) { 
println(x); println(y) 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Scala’s Functional Features 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Scala’s Functional Features 
Functions are software modules (objects in 
Scala’s parlance). 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Scala’s Functional Features 
Functions are software modules (objects in 
Scala’s parlance). 
Users can define anonymous functions. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Scala’s Functional Features 
Functions are software modules (objects in 
Scala’s parlance). 
Users can define anonymous functions. 
var inc = (x:Int) => x+1 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Scala’s Functional Features 
Functions are software modules (objects in 
Scala’s parlance). 
Users can define anonymous functions. 
var inc = (x:Int) => x+1 
. . . . . . 
Supports closures.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Scala’s Functional Features 
Functions are software modules (objects in 
Scala’s parlance). 
Users can define anonymous functions. 
var inc = (x:Int) => x+1 
. . . . . . 
Supports closures. 
var mul = (x: Int) => (y:Int) => x*y 
var mul3 = mul(3)
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Scala’s Functional Features 
Functions are software modules (objects in 
Scala’s parlance). 
Users can define anonymous functions. 
var inc = (x:Int) => x+1 
. . . . . . 
Supports closures. 
var mul = (x: Int) => (y:Int) => x*y 
var mul3 = mul(3) 
Pattern matching.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Data Structures with Class Hierarchies 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Data Structures with Class Hierarchies 
. . . . . . 
Haskell binary tree
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Data Structures with Class Hierarchies 
. . . . . . 
Haskell binary tree 
datatype BinTree = Empty | 
Node(Int, BinTree, BinTree)
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Data Structures with Class Hierarchies 
. . . . . . 
Haskell binary tree 
datatype BinTree = Empty | 
Node(Int, BinTree, BinTree) 
Scala binary tree
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Data Structures with Class Hierarchies 
. . . . . . 
Haskell binary tree 
datatype BinTree = Empty | 
Node(Int, BinTree, BinTree) 
Scala binary tree 
abstract class BinTree 
case object EmptyTree extends BinTree 
case class Node(elem : Int, 
left : BinTree, 
right: BinTree) extends BinTree
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Pattern Matching in Action 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Pattern Matching in Action 
. . . . . . 
Depth of a binary tree
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Pattern Matching in Action 
. . . . . . 
Depth of a binary tree 
def depth(t: BinTree): Int = { 
t match { 
case EmptyTree => 0 
case Node(_,EmptyTree,r) => 1 + depth(r) 
case Node(_,l,EmptyTree) => 1 + depth(l) 
case Node(_,l,r) => Math.max(depth(l), 
depth(r)) + 1 
} 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Constructing Parsers with Parser Builders 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Constructing Parsers with Parser Builders 
Tools that can be combined to build real parsers. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Constructing Parsers with Parser Builders 
Tools that can be combined to build real parsers. 
A toy parser that accepts binary numerals. 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Constructing Parsers with Parser Builders 
Tools that can be combined to build real parsers. 
A toy parser that accepts binary numerals. 
import scala.util.parsing.combinator._ 
class BinDigit extends JavaTokenParsers { 
def D = "0" | "1" 
def B = D~rep(D) 
def parse(text : String) = parseAll(B,text) 
} 
var P = new BinDigit 
println("input : "+args(0)) 
println(P.parse(args(0))) 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing 
Variables can be assigned XML content.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing 
Variables can be assigned XML content. 
var poem = 
<poem> <title> Magic Everywhere </title> 
<poet realname="yes"> Tom Jones </poet> 
<stanza> <verse> magic everywhere </verse> 
</stanza> </poem> 
println(poem)
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing 
Variables can be assigned XML content. 
var poem = 
<poem> <title> Magic Everywhere </title> 
<poet realname="yes"> Tom Jones </poet> 
<stanza> <verse> magic everywhere </verse> 
</stanza> </poem> 
println(poem) 
Or they can be assigned XML content stored in files.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing 
Variables can be assigned XML content. 
var poem = 
<poem> <title> Magic Everywhere </title> 
<poet realname="yes"> Tom Jones </poet> 
<stanza> <verse> magic everywhere </verse> 
</stanza> </poem> 
println(poem) 
Or they can be assigned XML content stored in files. 
val x = XML.loadFile("listdir.html")
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing 
Saving XML content.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing 
Saving XML content. 
var z = <person> 
<name>Blaise</name> <surname>Pascal</surname> 
</person> 
XML.save("persons.xml",z)
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing 
Saving XML content. 
var z = <person> 
<name>Blaise</name> <surname>Pascal</surname> 
</person> 
XML.save("persons.xml",z) 
Example: Find all poems that have been published 
after 1960 and print the title and the poet of each 
such poem.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
XML Processing 
Saving XML content. 
var z = <person> 
<name>Blaise</name> <surname>Pascal</surname> 
</person> 
XML.save("persons.xml",z) 
Example: Find all poems that have been published 
after 1960 and print the title and the poet of each 
such poem. 
for ( val poem <- poems  "poem" ) { 
if ( (poem  "year").text.trim.toInt > 1960 ) { 
var poet = (poem  "poet").text 
var title = (poem  "title").text 
println("""+title+"" by "+poet) 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Truths
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Truths 
EETimes Europe 
(http://www.electronics-eetimes.com): “As 
Moore’s Law runs out of steam and computing 
goes mobile, technologists are searching for 
ways to make the leap to new parallel 
programming frameworks that can leverage 
low-power multicore architectures.”
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Truths 
EETimes Europe 
(http://www.electronics-eetimes.com): “As 
Moore’s Law runs out of steam and computing 
goes mobile, technologists are searching for 
ways to make the leap to new parallel 
programming frameworks that can leverage 
low-power multicore architectures.”
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Truths 
EETimes Europe 
(http://www.electronics-eetimes.com): “As 
Moore’s Law runs out of steam and computing 
goes mobile, technologists are searching for 
ways to make the leap to new parallel 
programming frameworks that can leverage 
low-power multicore architectures.” 
Concurrent programming is not only the next 
logical step in software development, but the 
next necessary step.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Truths 
EETimes Europe 
(http://www.electronics-eetimes.com): “As 
Moore’s Law runs out of steam and computing 
goes mobile, technologists are searching for 
ways to make the leap to new parallel 
programming frameworks that can leverage 
low-power multicore architectures.” 
Concurrent programming is not only the next 
logical step in software development, but the 
next necessary step.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Truths 
EETimes Europe 
(http://www.electronics-eetimes.com): “As 
Moore’s Law runs out of steam and computing 
goes mobile, technologists are searching for 
ways to make the leap to new parallel 
programming frameworks that can leverage 
low-power multicore architectures.” 
Concurrent programming is not only the next 
logical step in software development, but the 
next necessary step. 
All modern programming languages must 
provide constructs and libraries that will ease 
the construction of concurrent programs
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Scala and Concurrency 
Scala programmers can code concurrent structures 
with…
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Scala and Concurrency 
Scala programmers can code concurrent structures 
with… 
threads (i.e., Java’s legacy to Scala)
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Scala and Concurrency 
Scala programmers can code concurrent structures 
with… 
threads (i.e., Java’s legacy to Scala)
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Scala and Concurrency 
Scala programmers can code concurrent structures 
with… 
threads (i.e., Java’s legacy to Scala) 
mailboxes (something like actors)
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Scala and Concurrency 
Scala programmers can code concurrent structures 
with… 
threads (i.e., Java’s legacy to Scala) 
mailboxes (something like actors)
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Scala and Concurrency 
Scala programmers can code concurrent structures 
with… 
threads (i.e., Java’s legacy to Scala) 
mailboxes (something like actors) 
actors
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Creating threaded applications by 
extending class Thread 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Creating threaded applications by 
extending class Thread 
class PrintProgressMark(val mark: Char, 
val delay :Int) extends Thread { 
. . . . . . 
private var i = 0 
override def run(): Unit = 
try { 
while (i <= 100) { 
print(mark); i += 1; Thread.sleep(delay); 
} 
} catch { case ex : InterruptedException => return } 
} 
object threadExample { 
def main(args: Array[String]) { 
new PrintProgressMark('+', 40).start 
new PrintProgressMark('*', 100).start 
} 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Creating threaded applications by using 
trait Runnable 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Creating threaded applications by using 
trait Runnable 
class PrintProgressMark2(val mark: Char, 
val delay :Int) extends Runnable { 
. . . . . . 
private var i = 0 
override def run(): Unit = 
try { 
while (i <= 100) { 
print(mark); i += 1; Thread.sleep(delay_) 
} 
} catch { case ex : InterruptedException => return } 
} 
object threadExample2 { 
def main(args: Array[String]) { 
var plus = new PrintProgressMark2('+', 40) 
var ast = new PrintProgressMark2('*', 100) 
new Thread(plus).start(); new Thread(ast).start() 
} }
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of…
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors;
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors;
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and,
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and,
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and, 
a finite set of new actors created.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and, 
a finite set of new actors created.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and, 
a finite set of new actors created. 
Thus,
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and, 
a finite set of new actors created. 
Thus, 
behaviors are history sensitive;
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and, 
a finite set of new actors created. 
Thus, 
behaviors are history sensitive;
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and, 
a finite set of new actors created. 
Thus, 
behaviors are history sensitive; 
there is no presumed sequentiality in the actions 
an actor performs; and,
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and, 
a finite set of new actors created. 
Thus, 
behaviors are history sensitive; 
there is no presumed sequentiality in the actions 
an actor performs; and,
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
What is an actor? 
An actor is a computational agent which maps each 
incoming communication to a triple consisting of… 
a finite set of communications sent to other 
actors; 
a new behavior that will govern the response to 
the next communication processed; and, 
a finite set of new actors created. 
Thus, 
behaviors are history sensitive; 
there is no presumed sequentiality in the actions 
an actor performs; and, 
actor creation is an integral of the computational 
model.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A first example in actor programming 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
A first example in actor programming 
import scala.actors.Actor._ 
object actorsExample { 
def main(args: Array[String]) { 
var PrintProgressPlus = actor { 
var i = 0 
while (i <= max) { 
print('+'); i += 1; Thread.sleep(40) 
} } 
var PrintProgressTimes = actor { 
var i = 0 
while (i <= max) { 
print('*'); i += 1; Thread.sleep(100) 
} } 
1 // <--- block must end in result expression, 
} } // not in definition 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Defining a class that subclasses trait 
Actor 
. . . . . .
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
Defining a class that subclasses trait 
Actor 
import scala.actors._ 
class PrintProgressMark(val mark: Char, 
val delay :Int) extends Actor { 
. . . . . . 
private var i = 0 
def act: Unit = { 
while (i <= 100) { 
print(mark); i += 1; Thread.sleep(delay_) 
} 
} 
} 
object actorsExample { 
def main(args: Array[String]) { 
new PrintProgressMark('+', 40).start 
new PrintProgressMark('*', 100).start 
} 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Carl Hewitt in “Viewing Cotrol Structures as Patterns 
of Passing Messages” (Artificial Intelligence 8, 3 
(1977), 323–364)
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Carl Hewitt in “Viewing Cotrol Structures as Patterns 
of Passing Messages” (Artificial Intelligence 8, 3 
(1977), 323–364) 
“present[s] an approach to modelling intelligence in 
terms of a society of communicating 
knowledge-based problem solving experts”;
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Carl Hewitt in “Viewing Cotrol Structures as Patterns 
of Passing Messages” (Artificial Intelligence 8, 3 
(1977), 323–364) 
“present[s] an approach to modelling intelligence in 
terms of a society of communicating 
knowledge-based problem solving experts”;
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Carl Hewitt in “Viewing Cotrol Structures as Patterns 
of Passing Messages” (Artificial Intelligence 8, 3 
(1977), 323–364) 
“present[s] an approach to modelling intelligence in 
terms of a society of communicating 
knowledge-based problem solving experts”; 
“each of the experts can be viewed as a society that 
can be further decomposed in the same way until the 
primitive actors of the system are reached”;
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Carl Hewitt in “Viewing Cotrol Structures as Patterns 
of Passing Messages” (Artificial Intelligence 8, 3 
(1977), 323–364) 
“present[s] an approach to modelling intelligence in 
terms of a society of communicating 
knowledge-based problem solving experts”; 
“each of the experts can be viewed as a society that 
can be further decomposed in the same way until the 
primitive actors of the system are reached”;
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Carl Hewitt in “Viewing Cotrol Structures as Patterns 
of Passing Messages” (Artificial Intelligence 8, 3 
(1977), 323–364) 
“present[s] an approach to modelling intelligence in 
terms of a society of communicating 
knowledge-based problem solving experts”; 
“each of the experts can be viewed as a society that 
can be further decomposed in the same way until the 
primitive actors of the system are reached”; 
he was “investigating the nature of the 
communication mechanisms needed for effective 
problem-solving by a society of experts and the 
conventions of civilized discourse that make this 
possible.”
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Hewitt demonstrates these “principles” by 
showing how to compute the factorial function 
with actors:
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Hewitt demonstrates these “principles” by 
showing how to compute the factorial function 
with actors:
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Hewitt demonstrates these “principles” by 
showing how to compute the factorial function 
with actors: 
1. using a resursive procedure, that is, a procedure 
that uses replication and
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Hewitt demonstrates these “principles” by 
showing how to compute the factorial function 
with actors: 
1. using a resursive procedure, that is, a procedure 
that uses replication and
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Computing Factorials 
Hewitt demonstrates these “principles” by 
showing how to compute the factorial function 
with actors: 
1. using a resursive procedure, that is, a procedure 
that uses replication and 
2. an iterative procudure, that is, a procedure that 
relies on message passing to deliver a result.
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Actor Replication
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Actor Replication 
case class Val(a: Actor, n: Int) 
case class Res(n: Int) 
class Fact extends Actor { 
def act = 
react { 
case Val(a,0) => a ! Res(1) 
case Val(a,n) => 
var p = new Fact 
p.start 
p ! Val(self,n-1) 
react { case Val(_, m) => a ! Val(a, n*m) 
case Res(m) => a ! Val(a, n*m)} 
} 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Using Class Fact
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Using Class Fact 
object actorsExample { 
def main(args: Array[String]) { 
var factorial = actor { 
react { 
case Val(a,n) => 
var q = new Fact 
q.start 
q ! Val(self,n) 
react { case Val(_,f) => a ! Val(a,f) } 
} 
} 
factorial ! Val(self,6) 
react { case Val(_, n) => println(n) } 
} 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Iterative Actor
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Iterative Actor 
case class InitVal(a: Actor, n: Int) 
case class Val(a: Actor, n: Int, m: Int) 
object actorsExample { 
def main(args: Array[String]) { 
val loopActor = actor { 
var ResActor : Actor = null 
loop{ 
react { 
case Val(_,acc,1) => 
ResActor ! acc; exit("done") 
case Val(a,1,count) => 
ResActor = a 
self ! Val(self,count,count-1) 
case Val(a,acc,count) => 
self ! Val(self,acc*count,count-1) 
} 
} 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Using Class Fact
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
Using Class Fact 
var factorial = actor { 
react { 
case InitVal(a,0) => a ! InitVal(a, 1) 
case InitVal(a,1) => a ! InitVal(a, 1) 
case InitVal(a,n) => 
loopActor ! Val(self,1,n) 
react { case f: Int => a ! InitVal(a,f) } 
} 
} 
factorial ! InitVal(self,6) 
receive { case InitVal(_, n) => println(n) } 
} 
}
Scala: An 
OO Surprise 
Syropoulos 
Introduction 
What is Scala? 
Object Orientation 
Scalability 
Functional 
Features 
Parser 
Builders 
XML 
Processing 
XML 
Processing 
Concurrent 
Program-ming 
. . . . . . 
The end! 
Thank you so much for your attention!

More Related Content

What's hot (18)

PPTX
Android with kotlin course
Abdul Rahman Masri Attal
 
ZIP
Why Scala for Web 2.0?
Alex Payne
 
PPTX
Introduction to Scala
Rahul Jain
 
PDF
[A4]de view2012 scala-michinisougu
NAVER D2
 
PDF
Preparing for Scala 3
Martin Odersky
 
PPTX
Scala-Ls1
Aniket Joshi
 
PDF
CeedMath & CeedGL, Let's talk 3D...
rsebbe
 
PPTX
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
PPT
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
PDF
Using Scala for building DSLs
IndicThreads
 
PPT
Writing DSL's in Scala
Abhijit Sharma
 
PDF
Kotlin & arrow: the functional way
nluaces
 
PDF
Why Scala?
Alex Payne
 
PDF
Kotlin & Arrow the functional way
Thoughtworks
 
PPTX
OCL in EMF
Ashwani Sharma
 
KEY
Xtend - A Language Made for Java Developers
Sebastian Zarnekow
 
PPTX
Lecture 1 oop
Tony Apreku
 
Android with kotlin course
Abdul Rahman Masri Attal
 
Why Scala for Web 2.0?
Alex Payne
 
Introduction to Scala
Rahul Jain
 
[A4]de view2012 scala-michinisougu
NAVER D2
 
Preparing for Scala 3
Martin Odersky
 
Scala-Ls1
Aniket Joshi
 
CeedMath & CeedGL, Let's talk 3D...
rsebbe
 
Scala - The Simple Parts, SFScala presentation
Martin Odersky
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
Using Scala for building DSLs
IndicThreads
 
Writing DSL's in Scala
Abhijit Sharma
 
Kotlin & arrow: the functional way
nluaces
 
Why Scala?
Alex Payne
 
Kotlin & Arrow the functional way
Thoughtworks
 
OCL in EMF
Ashwani Sharma
 
Xtend - A Language Made for Java Developers
Sebastian Zarnekow
 
Lecture 1 oop
Tony Apreku
 

Viewers also liked (17)

PDF
An Overview of Social Media
Apostolos Syropoulos
 
PPT
kewarganegeraan
SMA negeri 2 padang
 
PPTX
AT Pokemon Go
Apostolos Syropoulos
 
PDF
Computing under Vagueness
Apostolos Syropoulos
 
PDF
Interaction and P systems
Apostolos Syropoulos
 
PPTX
Defamation on the Internet
Apostolos Syropoulos
 
PDF
Information Systems Security: An Overview
Apostolos Syropoulos
 
PPTX
Internet Defamation
Apostolos Syropoulos
 
PPT
LT_Internet_Addiction
Apostolos Syropoulos
 
PDF
Fuzzy Topological Systems
Apostolos Syropoulos
 
PDF
P Systems and Distributed Computing
Apostolos Syropoulos
 
PPTX
Online defamation
Apostolos Syropoulos
 
PPT
le livre des idees
Club Marsa
 
PPTX
RO internet impact on child and adolescent brain
Apostolos Syropoulos
 
PPTX
Themes of kanthapura by raja rao.
baldaniyavanita
 
PPTX
Dramatic poesy- French vs English
baldaniyavanita
 
PPTX
Spina bifida
Shreya Sahasrabudhe
 
An Overview of Social Media
Apostolos Syropoulos
 
kewarganegeraan
SMA negeri 2 padang
 
AT Pokemon Go
Apostolos Syropoulos
 
Computing under Vagueness
Apostolos Syropoulos
 
Interaction and P systems
Apostolos Syropoulos
 
Defamation on the Internet
Apostolos Syropoulos
 
Information Systems Security: An Overview
Apostolos Syropoulos
 
Internet Defamation
Apostolos Syropoulos
 
LT_Internet_Addiction
Apostolos Syropoulos
 
Fuzzy Topological Systems
Apostolos Syropoulos
 
P Systems and Distributed Computing
Apostolos Syropoulos
 
Online defamation
Apostolos Syropoulos
 
le livre des idees
Club Marsa
 
RO internet impact on child and adolescent brain
Apostolos Syropoulos
 
Themes of kanthapura by raja rao.
baldaniyavanita
 
Dramatic poesy- French vs English
baldaniyavanita
 
Spina bifida
Shreya Sahasrabudhe
 
Ad

Similar to Scala: An OO Surprise (20)

PDF
Scala Programming A comprehensive beginner s guide to Scala 2nd Edition Claud...
hakeshametwp
 
PDF
Infographic on Scala Programming Language
Paddy Lock
 
PDF
Scala Overview INFX 1616
Patrick Walter
 
PPTX
Ten Compelling Reasons to Go the Scala Development Way - Metadesign Solutions
MetaDesign Solutions
 
PPTX
Scala adoption by enterprises
Mike Slinn
 
PDF
Lecture1
Muhammad Fayyaz
 
ODP
A Tour Of Scala
fanf42
 
PDF
Programming Scala 3rd Edition Dean Wampler Dean Wampler
absovgleni
 
PPT
Why scala - executive overview
Razvan Cojocaru
 
PPTX
An Introduction to Scala
Brent Lemons
 
PPTX
Introduction to Scala language
Aaqib Pervaiz
 
PDF
The Scala Programming Language
Haim Michael
 
KEY
Scala
sryx
 
ZIP
Why Scala Presentation
guestc185e0e
 
PDF
Absorbing Scala Into Java Ecosystem
Eishay Smith
 
PPTX
Scala Introduction - Meetup Scaladores RJ
Rodrigo Lima
 
PPTX
Scalamen and OT
getch123
 
PDF
Get Programming with Scala MEAP V05 Daniela Sfregola
biruktresehb
 
PPTX
Beginning scala 02 15
lancegatlin
 
PDF
Scala Jump Start [Free Online Meetup in English]
Haim Michael
 
Scala Programming A comprehensive beginner s guide to Scala 2nd Edition Claud...
hakeshametwp
 
Infographic on Scala Programming Language
Paddy Lock
 
Scala Overview INFX 1616
Patrick Walter
 
Ten Compelling Reasons to Go the Scala Development Way - Metadesign Solutions
MetaDesign Solutions
 
Scala adoption by enterprises
Mike Slinn
 
Lecture1
Muhammad Fayyaz
 
A Tour Of Scala
fanf42
 
Programming Scala 3rd Edition Dean Wampler Dean Wampler
absovgleni
 
Why scala - executive overview
Razvan Cojocaru
 
An Introduction to Scala
Brent Lemons
 
Introduction to Scala language
Aaqib Pervaiz
 
The Scala Programming Language
Haim Michael
 
Scala
sryx
 
Why Scala Presentation
guestc185e0e
 
Absorbing Scala Into Java Ecosystem
Eishay Smith
 
Scala Introduction - Meetup Scaladores RJ
Rodrigo Lima
 
Scalamen and OT
getch123
 
Get Programming with Scala MEAP V05 Daniela Sfregola
biruktresehb
 
Beginning scala 02 15
lancegatlin
 
Scala Jump Start [Free Online Meetup in English]
Haim Michael
 
Ad

More from Apostolos Syropoulos (20)

PDF
A Presentation of Braga. It was made by students of school
Apostolos Syropoulos
 
PPTX
A short presentation of Italy made by students of a school in Cosimo, Sicily,...
Apostolos Syropoulos
 
PPTX
Social Media Algorithms - Part of the "Computers in out Life" Erasmus+ Project
Apostolos Syropoulos
 
PDF
A gentle introduction to Artificial Intelligence
Apostolos Syropoulos
 
PPTX
ΑΡΧΟΝΤΙΚΟ ΠΑΜΟΥΚΤΣΟΓΛΟΥ - Pamouktsoglu Mansion
Apostolos Syropoulos
 
PPTX
Το Ορφανοτροφείο Θηλέων Ξάνθης
Apostolos Syropoulos
 
PPTX
Το Αρχαιολογικό Μουσείο Αβδήρων
Apostolos Syropoulos
 
PPTX
Ταφικά έθιμα στα αρχαία Άβδηρα
Apostolos Syropoulos
 
PPTX
Το ορφανοτροφείο της Ξάνθης
Apostolos Syropoulos
 
PPTX
Μικρασιατική κατατστροφή - Μέρος 3
Apostolos Syropoulos
 
PPTX
Μικρασιατική κατατστροφή - Μέρος 2
Apostolos Syropoulos
 
PPTX
Αφιέρωμα στη Μικρά Ασία
Apostolos Syropoulos
 
PPTX
ΕΚΠΑΙΔΕΥΤΙΚΗ ΔΡΑΣΗ «ΙΧΝΙΛΑΤΩΝΤΑΣ ΤΟ ΠΑΡΕΛΘΟΝ ΤΟΥ ΤΟΠΟΥ ΜΑΣ».pptx
Apostolos Syropoulos
 
PDF
How to Convert Units of Measure
Apostolos Syropoulos
 
PDF
Συγγραφή μαθηματικού κειμένου με χρήση του XeLaTeX (Writing mathematical tex...
Apostolos Syropoulos
 
PDF
Inflected Forms of Nouns and Adjectives
Apostolos Syropoulos
 
PDF
Learning Simple Phrases in Greek
Apostolos Syropoulos
 
PDF
Computational Thinking and...the Greek Alphabet
Apostolos Syropoulos
 
PPTX
Το Αποτύπωμα του 1821 στον Τόπο μου
Apostolos Syropoulos
 
PDF
Παγκόσμια ημέρα της σταθεράς π=3,14...
Apostolos Syropoulos
 
A Presentation of Braga. It was made by students of school
Apostolos Syropoulos
 
A short presentation of Italy made by students of a school in Cosimo, Sicily,...
Apostolos Syropoulos
 
Social Media Algorithms - Part of the "Computers in out Life" Erasmus+ Project
Apostolos Syropoulos
 
A gentle introduction to Artificial Intelligence
Apostolos Syropoulos
 
ΑΡΧΟΝΤΙΚΟ ΠΑΜΟΥΚΤΣΟΓΛΟΥ - Pamouktsoglu Mansion
Apostolos Syropoulos
 
Το Ορφανοτροφείο Θηλέων Ξάνθης
Apostolos Syropoulos
 
Το Αρχαιολογικό Μουσείο Αβδήρων
Apostolos Syropoulos
 
Ταφικά έθιμα στα αρχαία Άβδηρα
Apostolos Syropoulos
 
Το ορφανοτροφείο της Ξάνθης
Apostolos Syropoulos
 
Μικρασιατική κατατστροφή - Μέρος 3
Apostolos Syropoulos
 
Μικρασιατική κατατστροφή - Μέρος 2
Apostolos Syropoulos
 
Αφιέρωμα στη Μικρά Ασία
Apostolos Syropoulos
 
ΕΚΠΑΙΔΕΥΤΙΚΗ ΔΡΑΣΗ «ΙΧΝΙΛΑΤΩΝΤΑΣ ΤΟ ΠΑΡΕΛΘΟΝ ΤΟΥ ΤΟΠΟΥ ΜΑΣ».pptx
Apostolos Syropoulos
 
How to Convert Units of Measure
Apostolos Syropoulos
 
Συγγραφή μαθηματικού κειμένου με χρήση του XeLaTeX (Writing mathematical tex...
Apostolos Syropoulos
 
Inflected Forms of Nouns and Adjectives
Apostolos Syropoulos
 
Learning Simple Phrases in Greek
Apostolos Syropoulos
 
Computational Thinking and...the Greek Alphabet
Apostolos Syropoulos
 
Το Αποτύπωμα του 1821 στον Τόπο μου
Apostolos Syropoulos
 
Παγκόσμια ημέρα της σταθεράς π=3,14...
Apostolos Syropoulos
 

Recently uploaded (20)

PDF
2025 Insilicogen Company English Brochure
Insilico Gen
 
PPTX
CLIMATE CHANGE BY SIR AHSAN HISTORY.pptx
GulFeroze
 
PDF
The scientific heritage No 163 (163) (2025)
The scientific heritage
 
PPTX
Renewable Energy Resources - Introduction
BhajneetSingh1
 
PDF
Plankton and Fisheries Bovas Joel Notes.pdf
J. Bovas Joel BFSc
 
PDF
Carbonate formation and fluctuating habitability on Mars
Sérgio Sacani
 
PDF
The Diversity of Exoplanetary Environments and the Search for Signs of Life B...
Sérgio Sacani
 
PDF
Portable Hyperspectral Imaging (pHI) for the enhanced recording of archaeolog...
crabbn
 
PDF
RANKING THE MICRO LEVEL CRITICAL FACTORS OF ELECTRONIC MEDICAL RECORDS ADOPTI...
hiij
 
PPTX
SCHOOL HOLIDAY REVISION CHAPTER 8.pptx science kssm
SITIATHIRAHBINTISULA
 
PDF
Rational points on curves -- BIMR 2025 --
mmasdeu
 
PDF
seedproductiontechniques-210522130809.pdf
sr5566mukku
 
PPTX
Presentation 1 Microbiome Engineering and Synthetic Microbiology.pptx
Prachi Virat
 
PPTX
Respiratory and Circulatory Sytems.pptpptx
AngeloAngeles17
 
PDF
Webinar: World's Smallest Pacemaker
Scintica Instrumentation
 
PPTX
SCIENCE 4 Q1- WEEK 2 DAY 1 Matatag Grade 4
AngieLeaSerraYlarde
 
PDF
Asthamudi lake and its fisheries&importance .pdf
J. Bovas Joel BFSc
 
PPTX
Microbes Involved In Malaria, Microbiology
UMME54
 
PDF
Historical Knowledge Bases with Semantic MediaWiki
BernhardKrabina
 
PDF
BlackBody Radiation experiment report.pdf
Ghadeer Shaabna
 
2025 Insilicogen Company English Brochure
Insilico Gen
 
CLIMATE CHANGE BY SIR AHSAN HISTORY.pptx
GulFeroze
 
The scientific heritage No 163 (163) (2025)
The scientific heritage
 
Renewable Energy Resources - Introduction
BhajneetSingh1
 
Plankton and Fisheries Bovas Joel Notes.pdf
J. Bovas Joel BFSc
 
Carbonate formation and fluctuating habitability on Mars
Sérgio Sacani
 
The Diversity of Exoplanetary Environments and the Search for Signs of Life B...
Sérgio Sacani
 
Portable Hyperspectral Imaging (pHI) for the enhanced recording of archaeolog...
crabbn
 
RANKING THE MICRO LEVEL CRITICAL FACTORS OF ELECTRONIC MEDICAL RECORDS ADOPTI...
hiij
 
SCHOOL HOLIDAY REVISION CHAPTER 8.pptx science kssm
SITIATHIRAHBINTISULA
 
Rational points on curves -- BIMR 2025 --
mmasdeu
 
seedproductiontechniques-210522130809.pdf
sr5566mukku
 
Presentation 1 Microbiome Engineering and Synthetic Microbiology.pptx
Prachi Virat
 
Respiratory and Circulatory Sytems.pptpptx
AngeloAngeles17
 
Webinar: World's Smallest Pacemaker
Scintica Instrumentation
 
SCIENCE 4 Q1- WEEK 2 DAY 1 Matatag Grade 4
AngieLeaSerraYlarde
 
Asthamudi lake and its fisheries&importance .pdf
J. Bovas Joel BFSc
 
Microbes Involved In Malaria, Microbiology
UMME54
 
Historical Knowledge Bases with Semantic MediaWiki
BernhardKrabina
 
BlackBody Radiation experiment report.pdf
Ghadeer Shaabna
 

Scala: An OO Surprise

  • 1. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Scala: An OO Surprise Apostolos Syropoulos Xanthi, Greece 4th European Lisp Symposium March 31st - April 1st, 2011 TUHH, Hamburg University of Technology, Hamburg, Germany . . . . . .
  • 2. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Outline 1. Introduction What is Scala? Object Orientation Scalability 2. Functional Features 3. Parser Builders 4. XML Processing 5. XML Processing 6. Concurrent Programming
  • 3. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language . . . . . .
  • 4. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. . . . . . .
  • 5. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. . . . . . .
  • 6. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. . . . . . .
  • 7. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. A scalable language. . . . . . .
  • 8. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. A scalable language. Has features found in functional programming languages, but it is not a functional langauge! . . . . . .
  • 9. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. A scalable language. Has features found in functional programming languages, but it is not a functional langauge! Allows concurrent programing. . . . . . .
  • 10. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. A scalable language. Has features found in functional programming languages, but it is not a functional langauge! Allows concurrent programing. . . . . . .
  • 11. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. A scalable language. Has features found in functional programming languages, but it is not a functional langauge! Allows concurrent programing. Includes facilities for GUI programming. . . . . . .
  • 12. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. A scalable language. Has features found in functional programming languages, but it is not a functional langauge! Allows concurrent programing. Includes facilities for GUI programming. Seamless integration of XML. . . . . . .
  • 13. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. A scalable language. Has features found in functional programming languages, but it is not a functional langauge! Allows concurrent programing. Includes facilities for GUI programming. Seamless integration of XML. . . . . . .
  • 14. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A versatile programming language A purely object-oriented language. Runs on the Java Virtual Machine. A scalable language. Has features found in functional programming languages, but it is not a functional langauge! Allows concurrent programing. Includes facilities for GUI programming. Seamless integration of XML. Provides parser combinators. . . . . . .
  • 15. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Principles of Object Orientation . . . . . .
  • 16. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Principles of Object Orientation Abstraction (i.e., a software object is an idealization of a real world object). . . . . . .
  • 17. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Principles of Object Orientation Abstraction (i.e., a software object is an idealization of a real world object). Encapsulation (i.e., a data protection mechanism). . . . . . .
  • 18. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Principles of Object Orientation Abstraction (i.e., a software object is an idealization of a real world object). Encapsulation (i.e., a data protection mechanism). Inheritance (i.e., an object may extend the functionality of another object). . . . . . .
  • 19. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Principles of Object Orientation Abstraction (i.e., a software object is an idealization of a real world object). Encapsulation (i.e., a data protection mechanism). Inheritance (i.e., an object may extend the functionality of another object). Polymorphism (i.e., software modules may have different instances with identical behavior). . . . . . .
  • 20. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming What makes a programming language scalable? . . . . . .
  • 21. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming What makes a programming language scalable? Any language that can be extended seamlessly is scalable. . . . . . .
  • 22. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming What makes a programming language scalable? Any language that can be extended seamlessly is scalable. Gyu L. Steel Jr.: “[A] language design can no longer be a thing. It must be a pattern–a pattern for growth–a pattern for growing the pattern for defining the patterns that programmers can use for their real work and their main goal.” . . . . . .
  • 23. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming What makes a programming language scalable? Any language that can be extended seamlessly is scalable. Gyu L. Steel Jr.: “[A] language design can no longer be a thing. It must be a pattern–a pattern for growth–a pattern for growing the pattern for defining the patterns that programmers can use for their real work and their main goal.” . . . . . .
  • 24. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming What makes a programming language scalable? Any language that can be extended seamlessly is scalable. Gyu L. Steel Jr.: “[A] language design can no longer be a thing. It must be a pattern–a pattern for growth–a pattern for growing the pattern for defining the patterns that programmers can use for their real work and their main goal.” There two forms of growth: variable vocabulary or variable semantics. . . . . . .
  • 25. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming What makes a programming language scalable? Any language that can be extended seamlessly is scalable. Gyu L. Steel Jr.: “[A] language design can no longer be a thing. It must be a pattern–a pattern for growth–a pattern for growing the pattern for defining the patterns that programmers can use for their real work and their main goal.” There two forms of growth: variable vocabulary or variable semantics. Generic types, operator overloading, and user-defined light-weight types form the kernel of every scalable language. . . . . . .
  • 26. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . A Generic Stack
  • 27. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . A Generic Stack class Stack [γ] (n: Int) { private var S = new Array[γ](n) private var top = 0; def push(elem: γ) { top = top + 1 S(top) = elem } def pop () : γ = { var oldtop = top top = top - 1 S(oldtop) } }
  • 28. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming User-Defined Light-Weight Complex Numbers . . . . . .
  • 29. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming User-Defined Light-Weight Complex Numbers class Complex(val re: Double, val im: Double) { def + (x: Complex) = new Complex(re + x.re, im + x.im) def unary_- = new Complex(-Re, -Im) . . . . . . . . . . . . . . . . . . override def toString = if(re == 0 && im == 0) "0" … } object Complex{ def apply(re: Double)(im: Double) = . . . . . . new Complex(re, im) } object i extends Complex(0.0, 1.0) . . . . . . . . . . . . . . . . . . . var a = 5 + 3.0*i // a complex number!!!
  • 30. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Call-By-Name or how to define new commands . . . . . .
  • 31. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Call-By-Name or how to define new commands def loop(pre: => Unit)(cond: => Boolean) (post: => Unit): Unit = { . . . . . . pre if (!cond) { post loop(pre)(cond)(post) } else () } var x=6; var y=0 loop { x=x-1; y=y+1 } (x == 0 ) { println(x); println(y) }
  • 32. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Scala’s Functional Features . . . . . .
  • 33. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Scala’s Functional Features Functions are software modules (objects in Scala’s parlance). . . . . . .
  • 34. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Scala’s Functional Features Functions are software modules (objects in Scala’s parlance). Users can define anonymous functions. . . . . . .
  • 35. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Scala’s Functional Features Functions are software modules (objects in Scala’s parlance). Users can define anonymous functions. var inc = (x:Int) => x+1 . . . . . .
  • 36. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Scala’s Functional Features Functions are software modules (objects in Scala’s parlance). Users can define anonymous functions. var inc = (x:Int) => x+1 . . . . . . Supports closures.
  • 37. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Scala’s Functional Features Functions are software modules (objects in Scala’s parlance). Users can define anonymous functions. var inc = (x:Int) => x+1 . . . . . . Supports closures. var mul = (x: Int) => (y:Int) => x*y var mul3 = mul(3)
  • 38. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Scala’s Functional Features Functions are software modules (objects in Scala’s parlance). Users can define anonymous functions. var inc = (x:Int) => x+1 . . . . . . Supports closures. var mul = (x: Int) => (y:Int) => x*y var mul3 = mul(3) Pattern matching.
  • 39. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Data Structures with Class Hierarchies . . . . . .
  • 40. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Data Structures with Class Hierarchies . . . . . . Haskell binary tree
  • 41. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Data Structures with Class Hierarchies . . . . . . Haskell binary tree datatype BinTree = Empty | Node(Int, BinTree, BinTree)
  • 42. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Data Structures with Class Hierarchies . . . . . . Haskell binary tree datatype BinTree = Empty | Node(Int, BinTree, BinTree) Scala binary tree
  • 43. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Data Structures with Class Hierarchies . . . . . . Haskell binary tree datatype BinTree = Empty | Node(Int, BinTree, BinTree) Scala binary tree abstract class BinTree case object EmptyTree extends BinTree case class Node(elem : Int, left : BinTree, right: BinTree) extends BinTree
  • 44. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Pattern Matching in Action . . . . . .
  • 45. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Pattern Matching in Action . . . . . . Depth of a binary tree
  • 46. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Pattern Matching in Action . . . . . . Depth of a binary tree def depth(t: BinTree): Int = { t match { case EmptyTree => 0 case Node(_,EmptyTree,r) => 1 + depth(r) case Node(_,l,EmptyTree) => 1 + depth(l) case Node(_,l,r) => Math.max(depth(l), depth(r)) + 1 } }
  • 47. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Constructing Parsers with Parser Builders . . . . . .
  • 48. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Constructing Parsers with Parser Builders Tools that can be combined to build real parsers. . . . . . .
  • 49. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Constructing Parsers with Parser Builders Tools that can be combined to build real parsers. A toy parser that accepts binary numerals. . . . . . .
  • 50. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Constructing Parsers with Parser Builders Tools that can be combined to build real parsers. A toy parser that accepts binary numerals. import scala.util.parsing.combinator._ class BinDigit extends JavaTokenParsers { def D = "0" | "1" def B = D~rep(D) def parse(text : String) = parseAll(B,text) } var P = new BinDigit println("input : "+args(0)) println(P.parse(args(0))) . . . . . .
  • 51. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing
  • 52. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing Variables can be assigned XML content.
  • 53. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing Variables can be assigned XML content. var poem = <poem> <title> Magic Everywhere </title> <poet realname="yes"> Tom Jones </poet> <stanza> <verse> magic everywhere </verse> </stanza> </poem> println(poem)
  • 54. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing Variables can be assigned XML content. var poem = <poem> <title> Magic Everywhere </title> <poet realname="yes"> Tom Jones </poet> <stanza> <verse> magic everywhere </verse> </stanza> </poem> println(poem) Or they can be assigned XML content stored in files.
  • 55. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing Variables can be assigned XML content. var poem = <poem> <title> Magic Everywhere </title> <poet realname="yes"> Tom Jones </poet> <stanza> <verse> magic everywhere </verse> </stanza> </poem> println(poem) Or they can be assigned XML content stored in files. val x = XML.loadFile("listdir.html")
  • 56. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing
  • 57. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing Saving XML content.
  • 58. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing Saving XML content. var z = <person> <name>Blaise</name> <surname>Pascal</surname> </person> XML.save("persons.xml",z)
  • 59. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing Saving XML content. var z = <person> <name>Blaise</name> <surname>Pascal</surname> </person> XML.save("persons.xml",z) Example: Find all poems that have been published after 1960 and print the title and the poet of each such poem.
  • 60. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . XML Processing Saving XML content. var z = <person> <name>Blaise</name> <surname>Pascal</surname> </person> XML.save("persons.xml",z) Example: Find all poems that have been published after 1960 and print the title and the poet of each such poem. for ( val poem <- poems "poem" ) { if ( (poem "year").text.trim.toInt > 1960 ) { var poet = (poem "poet").text var title = (poem "title").text println("""+title+"" by "+poet) }
  • 61. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Truths
  • 62. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Truths EETimes Europe (http://www.electronics-eetimes.com): “As Moore’s Law runs out of steam and computing goes mobile, technologists are searching for ways to make the leap to new parallel programming frameworks that can leverage low-power multicore architectures.”
  • 63. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Truths EETimes Europe (http://www.electronics-eetimes.com): “As Moore’s Law runs out of steam and computing goes mobile, technologists are searching for ways to make the leap to new parallel programming frameworks that can leverage low-power multicore architectures.”
  • 64. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Truths EETimes Europe (http://www.electronics-eetimes.com): “As Moore’s Law runs out of steam and computing goes mobile, technologists are searching for ways to make the leap to new parallel programming frameworks that can leverage low-power multicore architectures.” Concurrent programming is not only the next logical step in software development, but the next necessary step.
  • 65. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Truths EETimes Europe (http://www.electronics-eetimes.com): “As Moore’s Law runs out of steam and computing goes mobile, technologists are searching for ways to make the leap to new parallel programming frameworks that can leverage low-power multicore architectures.” Concurrent programming is not only the next logical step in software development, but the next necessary step.
  • 66. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Truths EETimes Europe (http://www.electronics-eetimes.com): “As Moore’s Law runs out of steam and computing goes mobile, technologists are searching for ways to make the leap to new parallel programming frameworks that can leverage low-power multicore architectures.” Concurrent programming is not only the next logical step in software development, but the next necessary step. All modern programming languages must provide constructs and libraries that will ease the construction of concurrent programs
  • 67. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Scala and Concurrency Scala programmers can code concurrent structures with…
  • 68. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Scala and Concurrency Scala programmers can code concurrent structures with… threads (i.e., Java’s legacy to Scala)
  • 69. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Scala and Concurrency Scala programmers can code concurrent structures with… threads (i.e., Java’s legacy to Scala)
  • 70. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Scala and Concurrency Scala programmers can code concurrent structures with… threads (i.e., Java’s legacy to Scala) mailboxes (something like actors)
  • 71. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Scala and Concurrency Scala programmers can code concurrent structures with… threads (i.e., Java’s legacy to Scala) mailboxes (something like actors)
  • 72. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Scala and Concurrency Scala programmers can code concurrent structures with… threads (i.e., Java’s legacy to Scala) mailboxes (something like actors) actors
  • 73. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Creating threaded applications by extending class Thread . . . . . .
  • 74. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Creating threaded applications by extending class Thread class PrintProgressMark(val mark: Char, val delay :Int) extends Thread { . . . . . . private var i = 0 override def run(): Unit = try { while (i <= 100) { print(mark); i += 1; Thread.sleep(delay); } } catch { case ex : InterruptedException => return } } object threadExample { def main(args: Array[String]) { new PrintProgressMark('+', 40).start new PrintProgressMark('*', 100).start } }
  • 75. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Creating threaded applications by using trait Runnable . . . . . .
  • 76. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Creating threaded applications by using trait Runnable class PrintProgressMark2(val mark: Char, val delay :Int) extends Runnable { . . . . . . private var i = 0 override def run(): Unit = try { while (i <= 100) { print(mark); i += 1; Thread.sleep(delay_) } } catch { case ex : InterruptedException => return } } object threadExample2 { def main(args: Array[String]) { var plus = new PrintProgressMark2('+', 40) var ast = new PrintProgressMark2('*', 100) new Thread(plus).start(); new Thread(ast).start() } }
  • 77. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of…
  • 78. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors;
  • 79. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors;
  • 80. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and,
  • 81. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and,
  • 82. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and, a finite set of new actors created.
  • 83. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and, a finite set of new actors created.
  • 84. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and, a finite set of new actors created. Thus,
  • 85. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and, a finite set of new actors created. Thus, behaviors are history sensitive;
  • 86. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and, a finite set of new actors created. Thus, behaviors are history sensitive;
  • 87. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and, a finite set of new actors created. Thus, behaviors are history sensitive; there is no presumed sequentiality in the actions an actor performs; and,
  • 88. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and, a finite set of new actors created. Thus, behaviors are history sensitive; there is no presumed sequentiality in the actions an actor performs; and,
  • 89. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . What is an actor? An actor is a computational agent which maps each incoming communication to a triple consisting of… a finite set of communications sent to other actors; a new behavior that will govern the response to the next communication processed; and, a finite set of new actors created. Thus, behaviors are history sensitive; there is no presumed sequentiality in the actions an actor performs; and, actor creation is an integral of the computational model.
  • 90. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A first example in actor programming . . . . . .
  • 91. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming A first example in actor programming import scala.actors.Actor._ object actorsExample { def main(args: Array[String]) { var PrintProgressPlus = actor { var i = 0 while (i <= max) { print('+'); i += 1; Thread.sleep(40) } } var PrintProgressTimes = actor { var i = 0 while (i <= max) { print('*'); i += 1; Thread.sleep(100) } } 1 // <--- block must end in result expression, } } // not in definition . . . . . .
  • 92. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Defining a class that subclasses trait Actor . . . . . .
  • 93. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming Defining a class that subclasses trait Actor import scala.actors._ class PrintProgressMark(val mark: Char, val delay :Int) extends Actor { . . . . . . private var i = 0 def act: Unit = { while (i <= 100) { print(mark); i += 1; Thread.sleep(delay_) } } } object actorsExample { def main(args: Array[String]) { new PrintProgressMark('+', 40).start new PrintProgressMark('*', 100).start } }
  • 94. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Carl Hewitt in “Viewing Cotrol Structures as Patterns of Passing Messages” (Artificial Intelligence 8, 3 (1977), 323–364)
  • 95. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Carl Hewitt in “Viewing Cotrol Structures as Patterns of Passing Messages” (Artificial Intelligence 8, 3 (1977), 323–364) “present[s] an approach to modelling intelligence in terms of a society of communicating knowledge-based problem solving experts”;
  • 96. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Carl Hewitt in “Viewing Cotrol Structures as Patterns of Passing Messages” (Artificial Intelligence 8, 3 (1977), 323–364) “present[s] an approach to modelling intelligence in terms of a society of communicating knowledge-based problem solving experts”;
  • 97. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Carl Hewitt in “Viewing Cotrol Structures as Patterns of Passing Messages” (Artificial Intelligence 8, 3 (1977), 323–364) “present[s] an approach to modelling intelligence in terms of a society of communicating knowledge-based problem solving experts”; “each of the experts can be viewed as a society that can be further decomposed in the same way until the primitive actors of the system are reached”;
  • 98. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Carl Hewitt in “Viewing Cotrol Structures as Patterns of Passing Messages” (Artificial Intelligence 8, 3 (1977), 323–364) “present[s] an approach to modelling intelligence in terms of a society of communicating knowledge-based problem solving experts”; “each of the experts can be viewed as a society that can be further decomposed in the same way until the primitive actors of the system are reached”;
  • 99. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Carl Hewitt in “Viewing Cotrol Structures as Patterns of Passing Messages” (Artificial Intelligence 8, 3 (1977), 323–364) “present[s] an approach to modelling intelligence in terms of a society of communicating knowledge-based problem solving experts”; “each of the experts can be viewed as a society that can be further decomposed in the same way until the primitive actors of the system are reached”; he was “investigating the nature of the communication mechanisms needed for effective problem-solving by a society of experts and the conventions of civilized discourse that make this possible.”
  • 100. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials
  • 101. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Hewitt demonstrates these “principles” by showing how to compute the factorial function with actors:
  • 102. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Hewitt demonstrates these “principles” by showing how to compute the factorial function with actors:
  • 103. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Hewitt demonstrates these “principles” by showing how to compute the factorial function with actors: 1. using a resursive procedure, that is, a procedure that uses replication and
  • 104. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Hewitt demonstrates these “principles” by showing how to compute the factorial function with actors: 1. using a resursive procedure, that is, a procedure that uses replication and
  • 105. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Computing Factorials Hewitt demonstrates these “principles” by showing how to compute the factorial function with actors: 1. using a resursive procedure, that is, a procedure that uses replication and 2. an iterative procudure, that is, a procedure that relies on message passing to deliver a result.
  • 106. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Actor Replication
  • 107. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Actor Replication case class Val(a: Actor, n: Int) case class Res(n: Int) class Fact extends Actor { def act = react { case Val(a,0) => a ! Res(1) case Val(a,n) => var p = new Fact p.start p ! Val(self,n-1) react { case Val(_, m) => a ! Val(a, n*m) case Res(m) => a ! Val(a, n*m)} } }
  • 108. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Using Class Fact
  • 109. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Using Class Fact object actorsExample { def main(args: Array[String]) { var factorial = actor { react { case Val(a,n) => var q = new Fact q.start q ! Val(self,n) react { case Val(_,f) => a ! Val(a,f) } } } factorial ! Val(self,6) react { case Val(_, n) => println(n) } } }
  • 110. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Iterative Actor
  • 111. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Iterative Actor case class InitVal(a: Actor, n: Int) case class Val(a: Actor, n: Int, m: Int) object actorsExample { def main(args: Array[String]) { val loopActor = actor { var ResActor : Actor = null loop{ react { case Val(_,acc,1) => ResActor ! acc; exit("done") case Val(a,1,count) => ResActor = a self ! Val(self,count,count-1) case Val(a,acc,count) => self ! Val(self,acc*count,count-1) } } }
  • 112. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Using Class Fact
  • 113. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . Using Class Fact var factorial = actor { react { case InitVal(a,0) => a ! InitVal(a, 1) case InitVal(a,1) => a ! InitVal(a, 1) case InitVal(a,n) => loopActor ! Val(self,1,n) react { case f: Int => a ! InitVal(a,f) } } } factorial ! InitVal(self,6) receive { case InitVal(_, n) => println(n) } } }
  • 114. Scala: An OO Surprise Syropoulos Introduction What is Scala? Object Orientation Scalability Functional Features Parser Builders XML Processing XML Processing Concurrent Program-ming . . . . . . The end! Thank you so much for your attention!