Imperative Programming 2: Circuit simulation
|
|
- Giles Wilkerson
- 6 years ago
- Views:
Transcription
1 Imperative Programming 2: Circuit simulation Hongseok Yang University of Oxford
2 Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, type-safe way. It smoothly integrates features of object-oriented functional languages... From
3 Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, type-safe way. It smoothly integrates features of object-oriented functional languages... object, class, From inheritance, mutable state (var)
4 Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, type-safe way. It smoothly integrates features of object-oriented functional languages... From pattern matching, high-order function, lazy evaluation
5 Today we will study programming idioms that use features of OO FP together. Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, type-safe way. It smoothly integrates features of object-oriented functional languages... From
6 Today s lecture We will develop a circuit simulator that uses both OO FP features. Expected outcome: Students can use the prog. idioms in the simulator for solving new problems. Based on Chapter 8.
7 Has anyone written a even-driven program such as a GUI program or an Android app before?
8 What about a scheduler?
9 Two programming idioms In their basic form, both idioms use an object that stores a list of functions in its var field: var l : List[() => Unit] First idiom : To schedule process dynamically generated tasks. Second idiom : To manage tasks that should be triggered when a certain event happens.
10 First idiom: Work-list algorithm class Scheduler { var worklist : List[() => Unit] = Nil def add(work: () => Unit) { worklist ::= work def run() { while (!worklist.isempty) { val item::rest = worklist worklist = rest item()
11 First idiom: Work-list algorithm class Scheduler { var worklist : List[() => Unit] = Nil def add(work: () => Unit) { worklist ::= work def run() { while (!worklist.isempty) { val item::rest = worklist worklist = rest item(). item() can call add modify worklist. 2. A more sophisticated scheduling policy.
12 First idiom: Work-list algorithm class Scheduler { var worklist : List[() => Unit] = Nil def add(work: () => Unit) { worklist ::= work def run() { while (!worklist.isempty) { val item::rest = worklist worklist = rest item(). item() can call add modify worklist. 2. A more sophisticated scheduling policy.
13 Second idiom: Observer pattern (Scala version) class Counter { var observers : List[() => Unit] = Nil var x : Int = 0 def add(work: () => Unit) { observers ::= work def inc() { x += observers foreach (_ ()) def get : Int = x
14 Second idiom: Observer pattern (Scala version) class Counter { var observers : List[() => Unit] = Nil var x : Int = 0 def add(work: () => Unit) { observers ::= work work() def inc() { x += observers foreach (_ ()) def get : Int = x
15 Second idiom: Observer pattern (Scala version) class Counter { var observers : List[() => Unit] = Nil var x : Int = 0 def add(work: () => Unit) { observers ::= work work() def inc() { x += observers foreach (_ ()) def get : Int = x
16 Second idiom: Observer pattern (Scala version) class Counter { var observers : List[() => Unit] = Nil var x : Int = 0 def add(o: () => Unit) { observers ::= o o() def inc() { x += observers foreach (_ ()) def get : Int = x
17 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it.
18 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or not
19 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. 0 or not
20 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or 0 0 not 0
21 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or 0 0 not 0
22 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or 0 0 not 0
23 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or 0 0 not 0
24 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or 0 not 0
25 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or not
26 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or not 0
27 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or 0 not 0
28 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or 0 not 0
29 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. or not val a,b = new Wire val d,e = new Wire val s,c = new Wire orgate(a,b,d) Gate(a,b,c) inverter(c,e) Gate(d,e,s) a setsignal true b setsignal false run
30 Programming challenge: Circuit simulator The simulator should allow us to describe a circuit to run it. 0 or not val a,b = new Wire val d,e = new Wire val s,c = new Wire orgate(a,b,d) Gate(a,b,c) inverter(c,e) Gate(d,e,s) a setsignal true b setsignal false run()
31 Programming challenge: [Q] Would you model wires as observables (corresponding to counters) or observers? Circuit simulator What about gates? The simulator should allow us to describe a circuit to run it. 0 or not val a,b = new Wire val d,e = new Wire val s,c = new Wire orgate(a,b,d) Gate(a,b,c) inverter(c,e) Gate(d,e,s) a setsignal true b setsignal false run()
32 MySim curtime = 2 worklist = [(3,t), (5,t2), (9,t3)] MySim schedules tasks. Work-list algorithm. (3,t) represents a task that should run function t at time 3.
33 MySim curtime = 2 worklist = [(3,t), (5,t2), (9,t3)] MySim schedules tasks. Work-list algorithm. (3,t) represents a task that should run function t at time 3. wire2 sigval = false obs = [f] wire wire3 sigval = false obs = [g] sigval = true obs = [h, h2] wiren uses the observer pattern. Logic gates are functions, observers of wires.
34 MySim curtime = 2 worklist = [(3,t), (5,t2), (9,t3)] MySim schedules tasks. Work-list algorithm. (3,t) represents a task that should run function t at time 3. wire2 wire sigval = false wire3 obs = [f] sigval = false wire2 wire obs = [g] gate sigval = true wire3 obs = [h, h2] wiren uses the observer pattern. Logic gates are functions, observers of wires.
35 MySim curtime = 3 worklist = [(5,t2), (9,t3)] MySim schedules tasks. Work-list algorithm. (3,t) represents a task that should run function t at time 3. wire2 wire sigval = true wire3 obs = [f] sigval = false wire2 wire obs = [g] gate sigval = true wire3 obs = [h, h2] wiren uses the observer pattern. Logic gates are functions, observers of wires.
36 MySim curtime = 3 worklist = [(5,t2), (9,t3)] MySim schedules tasks. Work-list algorithm. (3,t) represents a task that should run function t at time 3. wire2 wire sigval = true wire3 obs = [f] sigval = false wire2 wire obs = [g] gate sigval = true wire3 obs = [h, h2] wiren uses the observer pattern. Logic gates are functions, observers of wires.
37 MySim curtime = 3 worklist = [(4,t4), (5,t2), (9,t3)] MySim schedules tasks. Work-list algorithm. (3,t) represents a task that should run function t at time 3. wire2 wire sigval = true wire3 obs = [f] sigval = false wire2 wire obs = [g] gate sigval = true wire3 obs = [h, h2] wiren uses the observer pattern. Logic gates are functions, observers of wires.
38 MySim curtime = 4 worklist = [(5,t2), (9,t3)] MySim schedules tasks. Work-list algorithm. (3,t) represents a task that should run function t at time 3. wire2 wire sigval = true wire3 obs = [f] sigval = true wire2 wire obs = [g] gate sigval = true wire3 obs = [h, h2] wiren uses the observer pattern. Logic gates are functions, observers of wires.
39 Class hierarchy Work-list algo. Simulation Class & methods for wires & gates. MySim. Circuit Wire Nested class. wire, wire2,... Observer pattern.
40 Class hierarchy Work-list algo. Simulation Class & methods for wires & gates. MySim. Circuit Wire Nested class. wire, wire2,... Observer pattern.
41 abstract class Simulation { type Work = (Int, ()=>Unit) var curtime = 0 var worklist: List[Work] = Nil Work-list algo. Tasks sorted by time. private def insert(l:list[work], w:work): List[Work] = if (l.isempty w._ < l.head._) w::l else l.head :: insert(l.tail, w) def afterdelay(delay: Int)(block: => Unit) { val work = (curtime + delay, () => block) worklist = insert(worklist, work) def run() { afterdelay(0){ println( *** simulation start *** ) while (!worklist.isempty) { val (time, task) :: rest = worklist worklist = rest; curtime = time task()
42 abstract class Simulation { type Work = (Int, ()=>Unit) var curtime = 0 var worklist: List[Work] = Nil Work-list algo. Tasks sorted by time. private def insert(l:list[work], w:work): List[Work] = if (l.isempty w._ < l.head._) w::l else l.head :: insert(l.tail, w) def afterdelay(delay: Int)(block: => Unit) { val work = (curtime + delay, () => block) worklist = insert(worklist, work) def run() { afterdelay(0){ println( *** simulation start *** ) while (!worklist.isempty) { val (time, task) :: rest = worklist worklist = rest; curtime = time task()
43 abstract class Simulation { type Work = (Int, ()=>Unit) var curtime = 0 var worklist: List[Work] = Nil Work-list algo. Tasks sorted by time. private def insert(l:list[work], w:work): List[Work] = if (l.isempty w._ < l.head._) w::l else l.head :: insert(l.tail, w) def afterdelay(delay: Int)(block: => Unit) { val work = (curtime + delay, () => block) worklist = insert(worklist, work) def run() { afterdelay(0){ println( *** simulation start *** ) while (!worklist.isempty) { val (time, task) :: rest = worklist worklist = rest; curtime = time task() afterdelay adds a new work item. block is a by-name parameter. run executes items in worklist.
44 abstract class Simulation { type Work = (Int, ()=>Unit) var curtime = 0 var worklist: List[Work] = Nil Work-list algo. Tasks sorted by time. private def insert(l:list[work], w:work): List[Work] = if (l.isempty w._ < l.head._) w::l else l.head :: insert(l.tail, w) def afterdelay(delay: Int)(block: => Unit) { val work = (curtime + delay, () => block) worklist = insert(worklist, work) def run() { afterdelay(0){ println( *** simulation start *** ) while (!worklist.isempty) { val (time, task) :: rest = worklist worklist = rest; curtime = time task() afterdelay adds a new work item. block is a by-name parameter. run executes items in worklist.
45 abstract class Simulation { type Work = (Int, ()=>Unit) var curtime = 0 var worklist: List[Work] = Nil Work-list algo. Tasks sorted by time. private def insert(l:list[work], w:work): List[Work] = if (l.isempty w._ < l.head._) w::l else l.head :: insert(l.tail, w) def afterdelay(delay: Int)(block: => Unit) { val work = (curtime + delay, () => block) worklist = insert(worklist, work) [Q] Complete the def n of run. def run() { afterdelay(0){ println( *** simulation start *** ) while (!worklist.isempty) { val (time, task) :: rest = worklist worklist = rest; curtime = time task() afterdelay adds a new work item. block is a by-name parameter. run executes items in worklist.
46 abstract class Simulation { type Work = (Int, ()=>Unit) var curtime = 0 var worklist: List[Work] = Nil Work-list algo. Tasks sorted by time. private def insert(l:list[work], w:work): List[Work] = if (l.isempty w._ < l.head._) w::l else l.head :: insert(l.tail, w) def afterdelay(delay: Int)(block: => Unit) { val work = (curtime + delay, () => block) worklist = insert(worklist, work) [Q] Complete the def n of run. def run() { afterdelay(0){ println( *** simulation start *** ) while (!worklist.isempty) { val (time, task) :: rest = worklist worklist = rest; curtime = time task() afterdelay adds a new work item. block is a by-name parameter. run executes items in worklist.
47 abstract class Simulation { type Work = (Int, ()=>Unit) var curtime = 0 var worklist: List[Work] = Nil Work-list algo. Tasks sorted by time. private def insert(l:list[work], w:work): List[Work] = if (l.isempty w._ < l.head._) w::l else l.head :: insert(l.tail, w) def afterdelay(delay: Int)(block: => Unit) { val work = (curtime + delay, () => block) worklist = insert(worklist, work) [Q2] Find a resource invariant. def run() { afterdelay(0){ println( *** simulation start *** ) while (!worklist.isempty) { val (time, task) :: rest = worklist worklist = rest; curtime = time task() afterdelay adds a new work item. block is a by-name parameter. run executes items in worklist.
48 Class hierarchy Work-list algo. Simulation Class & methods for wires & gates. MySim. Circuit Wire Nested class. wire, wire2,... Observer pattern.
49 abstract class Circuit extends Simulation { def InverterDelay: Int def AndGateDelay: Int def OrGateDelay: Int Inheritance enables code reuse. Delays to be specified later. class Wire { private var sigval = false var observers: List[Work] = List() def getsignal = sigval def setsignal(s: Boolean) = if (s!= sigval) { sigval = s; observers foreach (_()) def addobs(o: ()=>Unit) { observers = o :: observers; o() def inverter(input: Wire, output: Wire) { def invertaction() { val inputsig = input.getsignal afterdelay(inverterdelay) { output setsignal!inputsig input addobs invertaction() def Gate(a: Wire, a2: Wire, output: Wire)... def orgate(a: Wire, a2: Wire, output: Wire)...
50 abstract class Circuit extends Simulation { def InverterDelay: Int def AndGateDelay: Int def OrGateDelay: Int Inheritance enables code reuse. Delays to be specified later. class Wire { private var sigval = false var observers: List[Work] = List() def getsignal = sigval def setsignal(s: Boolean) = if (s!= sigval) { sigval = s; observers foreach (_()) def addobs(o: ()=>Unit) { observers = o :: observers; o() def inverter(input: Wire, output: Wire) { def invertaction() { val inputsig = input.getsignal afterdelay(inverterdelay) { output setsignal!inputsig input addobs invertaction() def Gate(a: Wire, a2: Wire, output: Wire)... def orgate(a: Wire, a2: Wire, output: Wire)...
51 abstract class Circuit extends Simulation { def InverterDelay: Int def AndGateDelay: Int def OrGateDelay: Int Inheritance enables code reuse. Delays to be specified later. class Wire { private var sigval = false Nested class. var observers: List[Work] = Nil def getsignal = sigval def setsignal(s: Boolean) = if (s!= sigval) { sigval = s; observers foreach (_()) def addobs(o: ()=>Unit) { observers = o :: observers; o() Observer pattern. def inverter(input: Wire, output: Wire) { def invertaction() { val inputsig = input.getsignal afterdelay(inverterdelay) { output setsignal!inputsig input addobs invertaction() def Gate(a: Wire, a2: Wire, output: Wire)... def orgate(a: Wire, a2: Wire, output: Wire)...
52 abstract class Circuit extends Simulation { def InverterDelay: Int def AndGateDelay: Int def OrGateDelay: Int Inheritance enables code reuse. Delays to be specified later. class Wire { private var sigval = false var observers: List[()=>Unit] = Nil def getsignal = sigval def setsignal(s: Boolean) = if (s!= sigval) { sigval = s; observers foreach (_()) def addobs(o: ()=>Unit) { observers ::= o; o() Nested class. Observer pattern. def inverter(input: Wire, output: Wire) { def invertaction() { val inputsig = input.getsignal afterdelay(inverterdelay) { output setsignal!inputsig input addobs invertaction() def Gate(a: Wire, a2: Wire, output: Wire)... def orgate(a: Wire, a2: Wire, output: Wire)...
53 abstract class Circuit extends Simulation { def InverterDelay: Int def AndGateDelay: Int def OrGateDelay: Int Inheritance enables code reuse. Delays to be specified later. class Wire { private var sigval = false var observers: List[()=>Unit] = Nil def getsignal = sigval def setsignal(s: Boolean) = if (s!= sigval) { sigval = s; observers foreach (_()) def addobs(o: ()=>Unit) { observers ::= o; o() Nested class. Observer pattern. def inverter(input: Wire, output: Wire)... def invertaction() { val inputsig = input.getsignal afterdelay(inverterdelay) { output setsignal!inputsig input addobs invertaction() def Gate(a: Wire, a2: Wire, output: Wire)... def orgate(a: Wire, a2: Wire, output: Wire)...
54 abstract class Circuit extends Simulation { def InverterDelay: Int def AndGateDelay: Int def OrGateDelay: Int Inheritance enables code reuse. Delays to be specified later. class Wire { private var sigval = false var observers: List[()=>Unit] = Nil def getsignal = sigval def setsignal(s: Boolean) = if (s!= sigval) { sigval = s; observers foreach (_()) def addobs(o: ()=>Unit) { observers ::= o; o() Nested class. Observer pattern. Register an obs., def inverter(input: Wire, output: Wire) { def invertaction()... { val inputsig = input.getsignal afterdelay(inverterdelay) { output setsignal!inputsig input addobs invertaction def Gate(a: Wire, a2: Wire, output: Wire)... def orgate(a: Wire, a2: Wire, output: Wire)... which adds a task.
55 abstract class Circuit extends Simulation { def InverterDelay: Int def AndGateDelay: Int def OrGateDelay: Int Inheritance enables code reuse. Delays to be specified later. class Wire { private var sigval = false var observers: List[()=>Unit] = Nil def getsignal = sigval def setsignal(s: Boolean) = if (s!= sigval) { sigval = s; observers foreach (_()) def addobs(o: ()=>Unit) { observers ::= o; o() Nested class. Observer pattern. Register an obs., def inverter(input: Wire, output: Wire) { def invertaction() { val inputsig = input.getsignal afterdelay(inverterdelay) { output setsignal!inputsig input addobs invertaction def Gate(a: Wire, a2: Wire, output: Wire)... def orgate(a: Wire, a2: Wire, output: Wire)... which adds a task.
56 abstract class Circuit extends Simulation { def InverterDelay: Int def AndGateDelay: Int def OrGateDelay: Int Inheritance enables code reuse. Delays to be specified later. class Wire { private var sigval = false var observers: List[()=>Unit] = Nil def getsignal = sigval def setsignal(s: Boolean) = if (s!= sigval) { sigval = s; observers foreach (_()) def addobs(o: ()=>Unit) { observers ::= o; o() Nested class. Observer pattern. Register an obs., def inverter(input: Wire, output: Wire) { def invertaction() { val inputsig = input.getsignal afterdelay(inverterdelay) { output setsignal!inputsig input addobs invertaction def Gate(a: Wire, a2: Wire, output: Wire)... def orgate(a: Wire, a2: Wire, output: Wire)... which adds a task. [Q] Complete the def ns of Gate orgate.
57 abstract class Circuit extends Simulation { def InverterDelay: Int def AndGateDelay: Int def OrGateDelay: Int Inheritance enables code reuse. Delays to be specified later. class Wire { private var sigval = false var observers: List[Work] = Nil def getsignal = sigval def setsignal(s: Boolean) = def if Gate(a: (s!= sigval) Wire, { sigval a2: Wire, = s; output: observers Wire) foreach { (_()) def def addobs(o: Action() ()=>Unit) = { { observers ::= o; o() val asig = a.getsignal val a2sig = a2.getsignal def inverter(input: afterdelay(andgatedelay) Wire, output: { Wire) { def invertaction() output setsignal { (asig && a2sig) val inputsig = input.getsignal afterdelay(inverterdelay) { output setsignal!inputsig a addobs Action input a2 addobs Action invertaction def Gate(a: Wire, a2: Wire, output: Wire)... def orgate(a: Wire, a2: Wire, output: Wire)... Nested class. Observer pattern. Register an obs., which adds a task. [Q] Complete the def ns of Gate orgate.
58 Creating MySim object MySim extends Circuit { def InverterDelay = def AndGateDelay = 3 def OrGateDelay = 5 Creates a singleton object MySim that inherits specialises the abstract class Circuit. Simpler than the usual alternative.
59 Creating MySim object MySim extends Circuit { def InverterDelay = def AndGateDelay = 3 def OrGateDelay = 5 Creates a singleton object MySim that inherits specialises the abstract class Circuit. Simpler than the usual alternative. class MySimClass extends Circuit { def InverterDelay = def AndGateDelay = 3 def OrGateDelay = 5 val MySim = new MySimClass
60 Summary Two idioms for using high-order function mutable state together.. Work-list algorithm. 2. Observer pattern. I presented a simpler version of circuit simulation. Look at the textbook for a full version. Read Chapter 8.
Extended Example: Discrete Event Simulation
Extended Example: Discrete Event Simulation 1 Introduction This chapter shows by way of an extended example how objects and higher-order functions can be combined in interesting ways. The task is to design
More informationStateful Objects. can I withdraw 100 CHF? may vary over the course of the lifetime of the account.
Functions and State Functions and State Until now, our programs have been side-effect free. Therefore, the concept of time wasn t important. For all programs that terminate, any sequence of actions would
More informationWeek 8: Functions and States
Week 8: Functions and States Until now, our programs have been side-eect free. Therefore, the concept of time wasn't important. For all programs that terminate, any sequence of actions would have given
More informationImperative Programming 2: Traits
Imperative Programming 2: Traits Hongseok Yang University of Oxford Experience with traits so far In IP1, you have used traits as interfaces, in order to specify available methods and fields. trait IntQueue
More informationImperative Programming 2: Inheritance 1
Imperative Programming 2: Inheritance 1 Hongseok Yang University of Oxford Motivation Scala programs consist of classes, traits and singleton objects. Inheritance is a fundamental building block for relating
More informationCS205: Scalable Software Systems
CS205: Scalable Software Systems Lecture 4 September 14, 2016 Lecture 4 CS205: Scalable Software Systems September 14, 2016 1 / 16 Quick Recap Things covered so far Problem solving by recursive decomposition
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Week 13 - Part 1 Thomas Wies New York University Review Last lecture Object Oriented Programming Outline Today: Scala Sources: Programming in Scala, Second
More informationLinked lists and the List class
Linked lists and the List class Cheong 1 Linked lists So far, the only container object we used was the array. An array is a single object that contains references to other objects, possibly many of them.
More informationCS 2340 Objects and Design - Scala
CS 2340 Objects and Design - Scala Objects and Operators Christopher Simpkins chris.simpkins@gatech.edu Chris Simpkins (Georgia Tech) CS 2340 Objects and Design - Scala Objects and Operators 1 / 13 Classes
More informationCS Programming Languages: Scala
CS 3101-2 - Programming Languages: Scala Lecture 3: Fun with Functions Daniel Bauer (bauer@cs.columbia.edu) October 29, 2014 Daniel Bauer CS3101-2 Scala - 03 - Fun with Functions 1/37 Contents 1 Defining
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 21 March 2 nd, 2016 GUI: notifiers Transition to Java What is the type of xs? let r = {contents = 3} let xs = [(fun () -> r.contents
More informationScala. Fernando Medeiros Tomás Paim
Scala Fernando Medeiros fernfreire@gmail.com Tomás Paim tomasbmp@gmail.com Topics A Scalable Language Classes and Objects Basic Types Functions and Closures Composition and Inheritance Scala s Hierarchy
More informationGame Architecture Revisited
Lecture 8 Game Architecture Revisited Recall: The Game Loop 60 times/s = 16.7 ms Update Draw Receive player input Process player actions Process NPC actions Interactions (e.g. physics) Cull non-visible
More informationLife in a Post-Functional World
Life in a Post-Functional World Definitions Functional Programming Definitions Functional Programming Programming with functions! Definitions Functional Programming Programming with functions! Functions
More informationNotes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.)
Notes from a Short Introductory Lecture on Scala (Based on Programming in Scala, 2nd Ed.) David Haraburda January 30, 2013 1 Introduction Scala is a multi-paradigm language that runs on the JVM (is totally
More informationScala : an LLVM-targeted Scala compiler
Scala : an LLVM-targeted Scala compiler Da Liu, UNI: dl2997 Contents 1 Background 1 2 Introduction 1 3 Project Design 1 4 Language Prototype Features 2 4.1 Language Features........................................
More informationCS Programming Languages: Scala
CS 3101-2 - Programming Languages: Scala Lecture 5: Exceptions, Generic Classes Daniel Bauer (bauer@cs.columbia.edu) November 19, 2014 Daniel Bauer CS3101-2 Scala - 05 - Exceptions, Generic Classes 1/28
More informationAnnouncements. CSCI 334: Principles of Programming Languages. Lecture 16: Intro to Scala. Announcements. Squeak demo. Instructor: Dan Barowy
Announcements CSCI 334: Principles of Programming Languages Lecture 16: Intro to Scala HW7 sent out as promised. See course webpage. Instructor: Dan Barowy Announcements No class on Tuesday, April 17.
More informationOverview. Elements of Programming Languages. Advanced constructs. Motivating inner class example
Overview Elements of Programming Languages Lecture 11: Object-oriented functional programming James Cheney University of Edinburgh October 30, 2017 We ve now covered: basics of functional programming (with
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques () Lecture 20 February 28, 2018 Transition to Java Announcements HW05: GUI programming Due: THURSDAY!! at 11:59:59pm Lots of TA office hours today Thursday See Piazza
More informationECE 449 OOP and Computer Simulation Lecture 09 Logic Simulation
ECE 449 Object-Oriented Programming and Computer Simulation, Fall 2017, Dept. of ECE, IIT 1/31 ECE 449 OOP and Computer Simulation Lecture 09 Logic Simulation Professor Jia Wang Department of Electrical
More informationScala, Your Next Programming Language
Scala, Your Next Programming Language (or if it is good enough for Twitter, it is good enough for me) WORLDCOMP 2011 By Dr. Mark C. Lewis Trinity University Disclaimer I am writing a Scala textbook that
More informationQuestions. Exams: no. Get by without own Mac? Why ios? ios vs Android restrictions. Selling in App store how hard to publish? Future of Objective-C?
Questions Exams: no Get by without own Mac? Why ios? ios vs Android restrictions Selling in App store how hard to publish? Future of Objective-C? Grading: Lab/homework: 40%, project: 40%, individual report:
More informationCS111: PROGRAMMING LANGUAGE II
CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 1(c): Java Basics (II) Lecture Contents Java basics (part II) Conditions Loops Methods Conditions & Branching Conditional Statements A
More informationBibliography. Analyse et Conception Formelle. Lesson 5. Crash Course on Scala. Scala in a nutshell. Outline
Bibliography Analyse et Conception Formelle Lesson 5 Crash Course on Scala Simply Scala. Onlinetutorial: http://www.simply.com/fr http://www.simply.com/ Programming in Scala, M. Odersky, L. Spoon, B. Venners.
More informationThe fringe of a binary tree are the values in left-to-right order. For example, the fringe of the following tree:
Lecture 13 The Same Fringe Problem Given a binary tree: sealed trait BinTree [+A] case class Node [A]( lhs : BinTree [A], rhs : BinTree [A]) extends BinTree [A] case class Leaf [A]( x: A) extends BinTree
More informationWhat the optimizer does to your code
1 / 12 Miguel Garcia http://lamp.epfl.ch/~magarcia LAMP, EPFL 2012-04-18 2 / 12 Outline Things the optimizer is good at Example Pros and Cons Early inlining Parallelizing an optimization phase Further
More informationn n Official Scala website n Scala API n
n Quiz 8 Announcements n Rainbow grades: HW1-8, Quiz1-6, Exam1-2 n Still grading: HW9, Quiz 7 Scala n HW10 due today n HW11 out today, due Friday Fall 18 CSCI 4430, A Milanova 1 Today s Lecture Outline
More informationOverview. Elements of Programming Languages. Objects. Self-Reference
Overview Elements of Programming Languages Lecture 10: James Cheney University of Edinburgh October 23, 2017 Last time: programming in the large Programs, packages/namespaces, importing Modules and interfaces
More informationCompSci 220. Programming Methodology 12: Functional Data Structures
CompSci 220 Programming Methodology 12: Functional Data Structures A Polymorphic Higher- Order Function def findfirst[a](as: Array[A], p: A => Boolean): Int = { def loop(n: Int): Int = if (n >= as.length)
More informationTest 1 Summer 2014 Multiple Choice. Write your answer to the LEFT of each problem. 5 points each 1. Preprocessor macros are associated with: A. C B.
CSE 3302 Test 1 1. Preprocessor macros are associated with: A. C B. Java C. JavaScript D. Pascal 2. (define x (lambda (y z) (+ y z))) is an example of: A. Applying an anonymous function B. Defining a function
More informationCS162 Week 1. Kyle Dewey. Friday, January 10, 14
CS162 Week 1 Kyle Dewey Overview Basic Introduction CS Accounts Scala survival guide Office Hour Choose an hour from within: Tuesday/Thursday 11 AM - 1 PM Friday 11 AM - 4 PM Also available by appointment
More informationLecture 11: Subprograms & their implementation. Subprograms. Parameters
Lecture 11: Subprograms & their implementation Subprograms Parameter passing Activation records The run-time stack Implementation of static and dynamic scope rules Subprograms A subprogram is a piece of
More informationFirst Programming Language in CS Education The Arguments for Scala
First Programming Language in CS Education The Arguments for Scala WORLDCOMP 2011 By Dr. Mark C. Lewis Trinity University Disclaimer I am writing a Scala textbook that is under contract with CRC Press.
More informationCS205: Scalable Software Systems
CS205: Scalable Software Systems Lecture 3 September 5, 2016 Lecture 3 CS205: Scalable Software Systems September 5, 2016 1 / 19 Table of contents 1 Quick Recap 2 Type of recursive solutions 3 Translating
More informationCOMBINING PARTIAL EVALUATION AND SYMBOLIC EXECUTION
COMBINING PARTIAL EVALUATION AND SYMBOLIC EXECUTION Reiner Hähnle & Richard Bubel Chalmers University Symposium 09 Speyer CONTROL CIRCUIT y = 80; threshold = 100; if (y > threshold) { decrease = true;
More informationEnforcing Singularity
Dr. Michael Eichberg Software Engineering Department of Computer Science Technische Universität Darmstadt Software Engineering Enforcing Singularity For details see Gamma et al. in Design Patterns Enforcing
More informationA π-calculus Internal Domain-Specic Language for Scala
A π-calculus Internal Domain-Specic Language for Scala Pedro Matiello pmatiello@gmail.com Ana C. V. de Melo acvm@ime.usp.br π-calculus Syntax Prexes α ::= ȳ x Output y(x) Input τ Silent π-calculus Syntax
More informationInheritance and Interfaces
Inheritance and Interfaces what is inheritance? examples & Java API examples inheriting a method overriding a method polymorphism Object tostring interfaces Ex: sorting and Comparable interface Inheritance
More informationThe story so far. Elements of Programming Languages. While-programs. Mutable vs. immutable
The story so far Elements of Programming Languages Lecture 12: Imperative programming James Cheney University of Edinburgh November 4, 2016 So far we ve mostly considered pure computations. Once a variable
More informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 3 Thomas Wies New York University Review Last week Names and Bindings Lifetimes and Allocation Garbage Collection Scope Outline Control Flow Sequencing
More information8 Hiding Implementation Details
Object-Oriented Design Lecture 8 CS 3500 Spring 2011 (Pucella) Friday, Feb 4, 2011 8 Hiding Implementation Details Last time we saw the Interpreter Design Pattern as a rather mechanical way to get an implementation
More informationPractically Functional. Daniel Spiewak
Practically Functional Daniel Spiewak whoami Author of Scala for Java Refugees and other articles on Scala and FP Former editor Javalobby / EclipseZone Engaged in academic research involving Scala DSLs
More informationTopic 13: Packages and Imports
Topic 13: Packages and Imports Exercise Jesper Pedersen Notander Department of Computer Science Lund University Faculty of Engineering Learning Scala Seminar 3 Instructions Code Solution Instructions Study
More informationOverview. Elements of Programming Languages. Objects. Self-Reference
Overview Elements of Programming Languages Lecture 11: James Cheney University of Edinburgh November 3, 2015 Last time: programming in the large Programs, packages/namespaces, importing Modules and interfaces
More informationAn Overview of Scala. Philipp Haller, EPFL. (Lots of things taken from Martin Odersky's Scala talks)
An Overview of Scala Philipp Haller, EPFL (Lots of things taken from Martin Odersky's Scala talks) The Scala Programming Language Unifies functional and object-oriented programming concepts Enables embedding
More informationFlow of Control Branching 2. Cheng, Wei COMP May 19, Title
Flow of Control Branching 2 Cheng, Wei COMP110-001 May 19, 2014 Title Review of Previous Lecture If else Q1: Write a small program that Reads an integer from user Prints Even if the integer is even Otherwise,
More informationClassical Themes of Computer Science
Functional Programming (Part 1/2) Bernhard K. Aichernig Institute for Software Technology Graz University of Technology Austria Winter Term 2017/18 Version: November 22, 2017 1/49 Agenda I Functional Programming?
More informationCPL 2016, week 10. Clojure functional core. Oleg Batrashev. April 11, Institute of Computer Science, Tartu, Estonia
CPL 2016, week 10 Clojure functional core Oleg Batrashev Institute of Computer Science, Tartu, Estonia April 11, 2016 Overview Today Clojure language core Next weeks Immutable data structures Clojure simple
More informationSome Scala problems for self
Some Scala problems for self study@cs.lth.se May 4, 2012 2 Chapter 1 Getting Started 1.1 Background The book, Programming in Scala, Second Edition (PINS), is very good, and the best way to learn Scala
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 4 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationAxiomatic Rules. Lecture 18: Axiomatic Semantics & Type Safety. Correctness using Axioms & Rules. Axiomatic Rules. Steps in Proof
Lecture 18: Axiomatic Semantics & Type Safety CSCI 131 Fall, 2011 Kim Bruce Axiomatic Rules Assignment axiom: - {P [expression / id]} id := expression {P} - Ex: {a+47 > 0} x := a+47 {x > 0} - {x > 1} x
More informationCompany Predecessor Domain Concepts
1. Performance 2. Security 3. Productivity New PL in Industry PL Company Predecessor Domain Concepts Go C Systems Channels Type Inference ML modules GC Dart Javascript Web Types Rust C++ System Browser
More informationScala - Some essential concepts -
Scala - Some essential concepts - Marcel Lüthi Graphics and Vision Research Group Department of Mathematics and Computer Science University of Basel Programming an important activity Data preprocessing
More informationProgramming in Scala Second Edition
Programming in Scala Second Edition Martin Odersky, Lex Spoon, Bill Venners artima ARTIMA PRESS WALNUT CREEK, CALIFORNIA Contents Contents List of Figures List of Tables List of Listings Foreword Foreword
More informationSorting: Given a list A with n elements possessing a total order, return a list with the same elements in non-decreasing order.
Sorting The sorting problem is defined as follows: Sorting: Given a list A with n elements possessing a total order, return a list with the same elements in non-decreasing order. Remember that total order
More informationProblems with Concurrency. February 19, 2014
with Concurrency February 19, 2014 s with concurrency interleavings race conditions dead GUI source of s non-determinism deterministic execution model 2 / 30 General ideas Shared variable Access interleavings
More informationPractical Scala. Dianne Marsh Emerging Technology for the Enterprise Conference 03/26/2009
Practical Scala Dianne Marsh Emerging Technology for the Enterprise Conference dmarsh@srtsolutions.com 03/26/2009 Outline for Discussion Motivation and migration Demonstrate key implementation details
More informationTopic VIII. The state of the art Scala < > Scala By Example by M. Odersky. Programming Methods Laboratory, EPFL, 2008.
References: Topic VIII The state of the art Scala < www.scala-lang.org > Scala By Example by M. Odersky. Programming Methods Laboratory, EPFL, 2008. An overview of the Scala programming language by M.
More informationSWIFT - CLOSURES. Global Functions Nested Functions Closure Expressions. Have a name. Capture values from enclosing function
http://www.tutorialspoint.com/swift/swift_closures.htm SWIFT - CLOSURES Copyright tutorialspoint.com Closures in Swift are similar to that of self-contained functions organized as blocks and called anywhere
More informationRuby: Introduction, Basics
Ruby: Introduction, Basics Computer Science and Engineering College of Engineering The Ohio State University Lecture 3 Ruby vs Java: Similarities Imperative and object-oriented Classes and instances (ie
More informationStatic analysis and all that
Static analysis and all that Martin Steffen IfI UiO Spring 2014 uio Static analysis and all that Martin Steffen IfI UiO Spring 2014 uio Plan approx. 15 lectures, details see web-page flexible time-schedule,
More informationCSC Java Programming, Fall Java Data Types and Control Constructs
CSC 243 - Java Programming, Fall 2016 Java Data Types and Control Constructs Java Types In general, a type is collection of possible values Main categories of Java types: Primitive/built-in Object/Reference
More informationKotlin, Start? Start! (pluu) Android Developer GDG Korea Android Organizer
Kotlin, Start? Start! (pluu) Android Developer GDG Korea Android Organizer Agenda Kotlin Overview Kotlin?? Basic fun main(args: Array): Unit { println("hello, world!") Basic Function Keyword
More informationCS558 Programming Languages
CS558 Programming Languages Winter 2018 Lecture 7b Andrew Tolmach Portland State University 1994-2018 Dynamic Type Checking Static type checking offers the great advantage of catching errors early And
More informationA Whirlwind Tour of Scala. Kevin Kilroy October 2014
A Whirlwind Tour of Scala Kevin Kilroy October 2014 A Brief History of Scala... Created in 2001 by javac author 1995 created Pizza with 1998 created GJ with 1999 Joined EPFL Created Funnel 2001 Scala 2003
More informationFunctional Objects. Christopher Simpkins CS 3693, Fall Chris Simpkins (Georgia Tech) CS 3693 Scala / 1
Functional Objects Christopher Simpkins csimpkin@spsu.edu CS 3693, Fall 2011 Chris Simpkins (Georgia Tech) CS 3693 Scala 2011-08-29 1 / 1 Functional Objects Functional objects have immutable state. Immutable
More informationlow and not larger than high. 18 points
CSE 330 Test 1 (1 point) Spring 015 Multiple Choice. Write your answer to the LEFT of each problem. 3 points each 1. Lisp was invented at: A. IBM B. MIT C. Netscape D. Stanford. In C++, what operator is
More informationFunctions, Closures and Control Abstraction
Functions, Closures and Control Abstraction Christopher Simpkins csimpkin@spsu.edu CS 3693, Fall 2011 Chris Simpkins (Georgia Tech) CS 3693 Scala 2011-09-07 1 / 1 Aside: drop and take (Optional) homework:
More informationA Deep Dive Into Kotlin
A Deep Dive Into Kotlin By 1 About me (droidyue.com) @Flipboard China GDG 2 3 Kotlin An official language for Android recently Powered by Jetbrains 4 Why Kotlin Concise Safe interoperable tool-friendly
More informationIntroduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt
Introduction to Software Testing Chapter 2.4 Graph Coverage for Design Elements Paul Ammann & Jeff Offutt www.introsoftwaretesting.com OO Software and Designs Emphasis on modularity and reuse puts complexity
More informationCISC-124. Casting. // this would fail because we can t assign a double value to an int // variable
CISC-124 20180122 Today we looked at casting, conditionals and loops. Casting Casting is a simple method for converting one type of number to another, when the original type cannot be simply assigned to
More informationSeminar on Languages for Scientific Computing Aachen, 6 Feb Navid Abbaszadeh.
Scientific Computing Aachen, 6 Feb 2014 navid.abbaszadeh@rwth-aachen.de Overview Trends Introduction Paradigms, Data Structures, Syntax Compilation & Execution Concurrency Model Reference Types Performance
More information15 Multiple Inheritance and Traits
Object-Oriented Design Lecture 15 CS 3500 Fall 2010 (Pucella) Tuesday, Nov 9, 2010 15 Multiple Inheritance and Traits Recall our code for MList from last time. We defined MList to be a subtype of List,
More informationDeclarative concurrency. March 3, 2014
March 3, 2014 (DP) what is declarativeness lists, trees iterative comutation recursive computation (DC) DP and DC in Haskell and other languages 2 / 32 Some quotes What is declarativeness? ness is important
More informationCS-XXX: Graduate Programming Languages. Lecture 22 Class-Based Object-Oriented Programming. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 22 Class-Based Object-Oriented Programming Dan Grossman 2012 PL Issues for OOP? OOP lets you: 1. Build some extensible software concisely 2. Exploit an intuitive
More informationIntroduction to ML. Mooly Sagiv. Cornell CS 3110 Data Structures and Functional Programming
Introduction to ML Mooly Sagiv Cornell CS 3110 Data Structures and Functional Programming Typed Lambda Calculus Chapter 9 Benjamin Pierce Types and Programming Languages Call-by-value Operational Semantics
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2016 Lecture 6a Andrew Tolmach Portland State University 1994-2016 Functional Programming An alternative paradigm to imperative programming First-class functions Emphasis
More informationGood Coding Practices Spring 2018
CS18 Integrated Introduction to Computer Science Fisler, Nelson Contents Good Coding Practices Spring 2018 1 Introduction 1 2 The Don ts 1 3 The Dos 4 4 CS 18-Specific Practices 5 5 Style 6 1 Introduction
More informationSoftware Engineering Design & Construction
Winter Semester 17/18 Software Engineering Design & Construction Dr. Michael Eichberg Fachgebiet Softwaretechnik Technische Universität Darmstadt A Critical View on Inheritance 2 A Critical View On Inheritance
More informationCS6202: Advanced Topics in Programming Languages and Systems Lecture 0 : Overview
CS6202: Advanced Topics in Programming Languages and Systems Lecture 0 : Overview Advanced Language Features and Foundations Lecturer : Chin Wei Ngan Email : chinwn@comp.nus.edu.sg Office : S15 06-01 CS6202
More informationExperiences with Scala Across the College-Level Curriculum
Loyola University Chicago Loyola ecommons Emerging Technologies Laboratory Publications Computer Science: Faculty Publications and Other Works 4-21-2017 Experiences with Scala Across the College-Level
More informationJava Basics. Object Orientated Programming in Java. Benjamin Kenwright
Java Basics Object Orientated Programming in Java Benjamin Kenwright Outline Essential Java Concepts Syntax, Grammar, Formatting, Introduce Object-Orientated Concepts Encapsulation, Abstract Data, OO Languages,
More informationCS558 Programming Languages
CS558 Programming Languages Fall 2017 Lecture 7b Andrew Tolmach Portland State University 1994-2017 Type Inference Some statically typed languages, like ML (and to a lesser extent Scala), offer alternative
More informationGrade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline
Grade Weights Language Design and Overview of COOL CS143 Lecture 2 Project 0% I, II 10% each III, IV 1% each Midterm 1% Final 2% Written Assignments 10% 2.% each Prof. Aiken CS 143 Lecture 2 1 Prof. Aiken
More informationReactive Behavior in Object-oriented Applications: An Analysis and a Research Roadmap
Reactive Behavior in Object-oriented Applications: An Analysis and a Research Roadmap Guido Salvaneschi Mira Mezini Software Technology Group, University of Darmstadt Outline Design space of OO reactive
More informationOutline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations
Outline Computer Science 331 Data Structures, Abstract Data Types, and Their Implementations Mike Jacobson 1 Overview 2 ADTs as Interfaces Department of Computer Science University of Calgary Lecture #8
More informationLecture 24. GUI Applications
Lecture 24 GUI Applications Announcements for This Lecture Assignments A6 due midnight TONIGHT Last day for consultants Also, fill out survey A7 due December 11 Instructions posted today Focus of today
More informationFigure 1: A complete binary tree.
The Binary Heap A binary heap is a data structure that implements the abstract data type priority queue. That is, a binary heap stores a set of elements with a total order (that means that every two elements
More informationINF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors.
INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION Instructors: Crista Lopes Copyright Instructors. Topics Recursion Higher-order functions Continuation-Passing Style Monads (take 1) Identity Monad Maybe
More informationIntroduction to Programming using C++
Introduction to Programming using C++ Lecture One: Getting Started Carl Gwilliam gwilliam@hep.ph.liv.ac.uk http://hep.ph.liv.ac.uk/~gwilliam/cppcourse Course Prerequisites What you should already know
More informationLecture 22: Garbage Collection 10:00 AM, Mar 16, 2018
CS18 Integrated Introduction to Computer Science Fisler, Nelson Lecture 22: Garbage Collection 10:00 AM, Mar 16, 2018 Contents 1 What is Garbage Collection? 1 1.1 A Concrete Example....................................
More informationConstants, once routines, and helper functions
Chair of Software Engineering Constants, once routines, and helper functions these slides contain advanced material and are optional Basic constants Defining constants for basic types in Eiffel class CONSTANTS
More informationReal World Scala and Wicket
Real World Scala and Wicket Jan Kriesten - Agenda 2 Introduction Functional IModel Don t Repeat Yourself / traits The Lazy Programmer Q & A, References Introduction About 4 Small company located in Hamburg
More informationFunctional Programming in Scala. Raj Sunderraman
Functional Programming in Scala Raj Sunderraman Programming Paradigms imperative programming modifying mutable variables, using assignments, and control structures such as if-then-else, loops, continue,
More informationSoftware Engineering: Design & Construction
Software Engineering: Design & Construction Department of Computer Science Software Technology Group Practice Exam May 22, 2015 First Name Last Name Matriculation Number Course of Study Department Signature
More informationThe Sun s Java Certification and its Possible Role in the Joint Teaching Material
The Sun s Java Certification and its Possible Role in the Joint Teaching Material Nataša Ibrajter Faculty of Science Department of Mathematics and Informatics Novi Sad 1 Contents Kinds of Sun Certified
More informationCOSE212: Programming Languages. Lecture 3 Functional Programming in OCaml
COSE212: Programming Languages Lecture 3 Functional Programming in OCaml Hakjoo Oh 2017 Fall Hakjoo Oh COSE212 2017 Fall, Lecture 3 September 18, 2017 1 / 44 Why learn ML? Learning ML is a good way of
More informationScala, Lift and the Real Time Web
Scala, Lift and the Real Time Web David Pollak Benevolent Dictator for Life Lift Web Framework dpp@liftweb.net All about me (David Pollak) Sometimes strict, mostly lazy Lead developer for Lift Web Framework
More informationProgramming Languages
CSE 130 : Spring 2011 Programming Languages Lecture 3: Crash Course Ctd, Expressions and Types Ranjit Jhala UC San Diego A shorthand for function binding # let neg = fun f -> fun x -> not (f x); # let
More information