Streams… …row, row, row your boat….

Slides:



Advertisements
Similar presentations
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 5. 2 List Utilities Scheme built-in procedures –(list x y z...) –(list-ref lst index) –(length lst) –(append.
Advertisements

Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
College of Information Technology & Design
C. Varela; Adapted from S. Haridi and P. Van Roy1 Declarative Programming Techniques Lazy Execution (VRH 4.5) Carlos Varela RPI Adapted with permission.
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
CSE 341 Lecture 16 More Scheme: lists; helpers; let/let*; higher-order functions; lambdas slides created by Marty Stepp
Slide 1 CS3 Fall 2005 Lecture week 13: Introduction to the Big Project.
Data Abstraction… The truth comes out…. What we’re doing today… Abstraction ADT: Dotted Pair ADT: List Box and Pointer List Recursion Deep List Recursion.
Chapter 15 Functional Programming Languages. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Design of imperative languages is.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 13. Streams 3.5, pages definitions file on web 2.
Feb 28More complicated recursions March 7Tree recursion, etc. Number-spelling Miniproject (#2) March 14Higher order procedures March 21Spring Break March.
CS 3 Final Review Gilbert Chou, Jenny Franco and Colleen Lewis December 14, pm GPB.
( (lambda (z) (define x (lambda (x) (lambda (y z) (y x)))) ( ( (x (lambda () z)) (lambda (z) z) 3 ) ) ) 2)
Midterm Exam Answers The Programming Language Landscape Robert Dewar.
PPL Pairs, lists and data abstraction. Data Abstraction? An interface: separate implementation from usage Think of the Map interface in Java: we know.
Spring 2008Programming Development Techniques 1 Topic 6 Hierarchical Data and the Closure Property Section September 2008.
1 Lecture OO, the notion of inheritance 3 Stacks in OO style (define (make-stack) (let ((top-ptr '())) (define (empty?) (null? top-ptr)) (define.
Chapter 9: Functional Programming in a Typed Language.
Adding Integers. The Number Line Integers = {…, -2, -1, 0, 1, 2, …} -505.
PPL Lazy Lists. Midterm 2012 (define sum-vals (λ (ts) (if (ts-simple? ts) (ts-val ts) (accumulate + 0 (map ts-val (ts-inner-slots ts))))))
David Evans CS200: Computer Science University of Virginia Computer Science Class 32: The Meaning of Truth.
 A sequence is a list of objects arranged in a specific order.  A sequence in computer science is known as an array. An array hold objects of the same.
1 מבוא מורחב למדעי המחשב בשפת Scheme תרגול Outline Mutable list structure RPN calculator Vectors and sorting.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 6. 2 List Utilities Scheme built-in procedures –(list x y z...) –(list-ref lst index) –(length lst) –(append.
Logic Programming (Control and Backtracking). Contents Logic Programming –sans Control –with Backtracking Streams.
Calculate the Following (Group A): – – (-5) (-5) 5. 3 – (+5)
CSE 341 Lecture 21 delayed evaluation; thunks; streams slides created by Marty Stepp
Abstraction A way of managing complexity for large programs A means of separating details of computation from use of computation Types of Abstraction Data.
WHAT IS BINARY? Binary is a number system that only uses two digits: 1 and 0. Any information that processed by a computer it is put into sequence of.
CS314 – Section 5 Recitation 9
Additional Scheme examples
13.4 Product of Two Matrices
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2017.
Lecture 16 Streams continue Infinite Streams מבוא מורחב - שיעור 16.
6.001 SICP Variations on a Scheme
Pairs and Lists. Data Abstraction. SICP: Sections – 2.2.1
PPL Lecture Notes: Chapter 3 High-Order Procedures Revisited.
PPL Lazy Lists.
Racket CSC270 Pepper major portions credited to
Stacks.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Winter 2013.
Closures and Streams cs784(Prasad) L11Clos
Binomial Priority Queues
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Zach Tatlock Winter 2018.
6.001 SICP Data abstractions
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2013.
Lecture 8: Recursion Practice CS200: Computer Science
Streams Sections 3.5.1,3.5.2 Pages
Lecture 18 Infinite Streams and
Lesson 7-1 Multiplying Monomials
PPL Sequence Interface.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2016.
Lecture 18.
Dynamic Scoping Lazy Evaluation
Lecture #8 מבוא מורחב.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Autumn 2017.
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Autumn 2018.
6.001 SICP Streams – the lazy way
Delayed Evaluation Special forms in Scheme (e.g., if and cond) do not use applicative order evaluation Only one of two or more expressions is actually.
Streams, Delayed Evaluation and a Normal Order Interpreter

Dan Grossman / Eric Mullen Autumn 2017
Today’s topics Abstractions Procedural Data
Binomial Priority Queues
books WARM-uP Lesson 1 Independent work Exit card
Rehearsal: Lazy Evaluation Infinite Streams in our lazy evaluator
Lisp.
Brett Wortzman Summer 2019 Slides originally created by Dan Grossman
CSE341: Programming Languages Lecture 14 Thunks, Laziness, Streams, Memoization Dan Grossman Spring 2019.
Presentation transcript:

Streams… …row, row, row your boat…

Agenda SUPER Brief intro to streams… Midterm Review Next Time…more streams & Scheme written in Scheme! (MCE)

Brief Intro to Streams Creates a sequence, but computes it only when requested! So the answer is outputted when program needs it, not when the program is called Promise!

Stream ADT Constructors Selectors cons-stream (cons-stream 1 2)  (cons 1 (delay 2)) Selectors stream-car (stream-car (cons-stream 1 2))  1 stream-cdr (stream-cdr (cons-stream 1 2))  2

Stream Procedures… stream-map stream-append Interleave stream-null? Works similarly like map for lists, but with streams Ex. (ss (stream-map + ones integers))  (2 3 4 5 6 7 8 …) ;; it adds the first element of each stream together, then adds the second element of both streams together etc. … (1+1 1+2 1+3 etc.) stream-append Works similarly to append, but it only works on finite streams where the last element is the-empty-stream Ex. (ss (stream-append (cons-stream 1 the-empty-stream) (cons-stream 2 the-empty-stream))) Interleave It takes two streams and interchanges their values and produces a new stream Ex. (ss (interleave ones twos))  (1 2 1 2 1 2 1 2 …) stream-null? The-empty-stream indicates whether a stream is null.

Null streams? Is there a null value for a stream? YES! It’s called the-empty-stream Below the line… (define (cons-stream a b) (cons a (delay b))) (define (stream-car stream) (car stream)) (define (stream-cdr stream) (force (cdr stream)))

Implicit Streams… Implicit streams Not using any other streams…ie (define ones (cons-stream 1 ones)) NOT implicit (define integers (cons-stream 1 (stream-map + ones integers)))

What’s the point? Benefit of efficiency…no long wait for an answer… Deferred operations until necessary. Think about being lazy and doing something only when you need to 

Stream Practice Create a stream repeater that takes an expression and generates this kind of stream: (ss (repeater ‘ha))  (ha haha hahaha …) Create a binary stream: (0 1 10 11 100 101 110 111 1000…)

…time for midterm review… More next time! …time for midterm review…