Administrative Stuff

Similar documents
Random Testing in 321

Random Testing in 321

Functional Programming - 2. Higher Order Functions

User-defined Functions. Conditional Expressions in Scheme

Cost of Substitution

Typed Racket: Racket with Static Types

Functional Programming. Pure Functional Programming

Typed Scheme: Scheme with Static Types

Racket: Modules, Contracts, Languages

Macros & Streams Spring 2018 Discussion 9: April 11, Macros

Delayed Expressions Fall 2017 Discussion 9: November 8, Iterables and Iterators. For Loops. Other Iterable Uses

The Typed Racket Guide

Computer Science 21b (Spring Term, 2015) Structure and Interpretation of Computer Programs. Lexical addressing

Higher-Order Functions

MORE SCHEME. 1 What Would Scheme Print? COMPUTER SCIENCE MENTORS 61A. October 30 to November 3, Solution: Solutions begin on the following page.

CSC 533: Programming Languages. Spring 2015

Fall 2017 Discussion 7: October 25, 2017 Solutions. 1 Introduction. 2 Primitives

Introduction to Typed Racket. The plan: Racket Crash Course Typed Racket and PL Racket Differences with the text Some PL Racket Examples

CS61A Notes 02b Fake Plastic Trees. 2. (cons ((1 a) (2 o)) (3 g)) 3. (list ((1 a) (2 o)) (3 g)) 4. (append ((1 a) (2 o)) (3 g))

Racket. CSE341: Programming Languages Lecture 14 Introduction to Racket. Getting started. Racket vs. Scheme. Example.

CS2500 Exam 2 Fall 2011

Summer 2017 Discussion 10: July 25, Introduction. 2 Primitives and Define

Vectors in Scheme. Data Structures in Scheme

Intro. Scheme Basics. scm> 5 5. scm>

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

Functional Programming. Pure Functional Languages

Project 2: Scheme Interpreter

ITERATORS AND STREAMS 9

CSE413: Programming Languages and Implementation Racket structs Implementing languages with interpreters Implementing closures

Streams, Delayed Evaluation and a Normal Order Interpreter. CS 550 Programming Languages Jeremy Johnson

Programming Languages. Next: Building datatypes. Suppose I wanted. Next: Building datatypes 10/4/2017. Review so far. Datatypes.

Deferred operations. Continuations Structure and Interpretation of Computer Programs. Tail recursion in action.

Spring 2018 Discussion 7: March 21, Introduction. 2 Primitives

Programming Languages. Datatypes

Recap from last time. Programming Languages. CSE 130 : Fall Lecture 3: Data Types. Put it together: a filter function

Principles of Programming Languages Topic: Functional Programming Professor L. Thorne McCarty Spring 2003

Functional Programming. Pure Functional Languages

11/6/17. Functional programming. FP Foundations, Scheme (2) LISP Data Types. LISP Data Types. LISP Data Types. Scheme. LISP: John McCarthy 1958 MIT

CSU211 Exam 2 Fall 2007

1. For every evaluation of a variable var, the variable is bound.

2D Syntax. Version October 30, 2017

Programming Languages

Documentation for LISP in BASIC

From Syntactic Sugar to the Syntactic Meth Lab:

Chapter 15 Functional Programming Languages

Module 8: Local and functional abstraction

Scheme in Scheme: The Metacircular Evaluator Eval and Apply

Programming Languages

CS61A Midterm 2 Review (v1.1)

Scheme. Functional Programming. Lambda Calculus. CSC 4101: Programming Languages 1. Textbook, Sections , 13.7

CS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.

Repetition Through Recursion

Lisp Basic Example Test Questions

SCHEME 8. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. March 23, 2017

(scheme-1) has lambda but NOT define

Object-oriented Programming and Software Engineering CITS1001. Multiple-choice Mid-semester Test

Higher-Order Functions (Part I)

Recap: ML s Holy Trinity

SCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015

Programming Languages. Thunks, Laziness, Streams, Memoization. Adapted from Dan Grossman s PL class, U. of Washington

CSE341 Autumn 2017, Final Examination December 12, 2017

Bindings & Substitution

CSE 130 [Winter 2014] Programming Languages

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

The Typed Racket Guide

Principles of Programming Languages

Recap: ML s Holy Trinity. Story So Far... CSE 130 Programming Languages. Datatypes. A function is a value! Next: functions, but remember.

CSE 130 Programming Languages. Datatypes. Ranjit Jhala UC San Diego

CSE 341 Section Handout #6 Cheat Sheet

FP Foundations, Scheme

Functional abstraction. What is abstraction? Eating apples. Readings: HtDP, sections Language level: Intermediate Student With Lambda

Functional abstraction

Name EID. (calc (parse '{+ {with {x {+ 5 5}} {with {y {- x 3}} {+ y y} } } z } ) )

CS 61A, Fall, 2002, Midterm #2, L. Rowe. 1. (10 points, 1 point each part) Consider the following five box-and-arrow diagrams.

(Provisional) Lecture 08: List recursion and recursive diagrams 10:00 AM, Sep 22, 2017

CS 314 Principles of Programming Languages. Lecture 16

CSE341 Spring 2017, Final Examination June 8, 2017

Fall Semester, The Metacircular Evaluator. Today we shift perspective from that of a user of computer langugaes to that of a designer of

CSE 130 Programming Languages. Lecture 3: Datatypes. Ranjit Jhala UC San Diego

Organization of Programming Languages CS3200/5200N. Lecture 11

Functional programming in μscheme

Below are example solutions for each of the questions. These are not the only possible answers, but they are the most common ones.

Sample midterm 1 #1. Problem 1 (What will Scheme print?).

CSE341 Spring 2017, Final Examination June 8, 2017

CS 415 Midterm Exam Fall 2003

How to Design Programs

Syntactic Sugar: Using the Metacircular Evaluator to Implement the Language You Want

CS450: Structure of Higher Level Languages Spring 2018 Assignment 7 Due: Wednesday, April 18, 2018

How to Design Programs Languages

Scheme Quick Reference

News. Programming Languages. Recap. Recap: Environments. Functions. of functions: Closures. CSE 130 : Fall Lecture 5: Functions and Datatypes

Structure and Interpretation of Computer Programs

Programming Languages

6.037 Lecture 7B. Scheme Variants Normal Order Lazy Evaluation Streams

SCHEME The Scheme Interpreter. 2 Primitives COMPUTER SCIENCE 61A. October 29th, 2012

Fall 2017 December 4, 2017

Wellesley College CS251 Programming Languages Spring, 2000 FINAL EXAM REVIEW PROBLEM SOLUTIONS

CS 275 Name Final Exam Solutions December 16, 2016

Fall 2018 Discussion 8: October 24, 2018 Solutions. 1 Introduction. 2 Primitives

Modern Programming Languages. Lecture LISP Programming Language An Introduction

Transcription:

Administrative Stuff Use the new version of PLAI from planet. It will download the first time you run a program with the 7, like this: #lang planet plai/plai:1:7 This lets you ignore passing test cases (put this at the top of your file): (print-only-errors #t) 1

Random Testing in 395 2

Test Cases So Far Each test relates a particular input to a particular output. (test (bound-ids (with 'x (id 'y) (id 'x))) '(x)) (test (binding-ids (with 'x (id 'y) (id 'x))) '(x)) 3

Property-based Testing But we can only write so many tests by hand. To find additional bugs, we can automate testing. We start with what we hope is a fact about our program. For example, If bound-ids says 'x is bound, then binding-ids says 'x is binding. 4

Property Violation If we can find some WAE for which the property doesn t hold... (define a-wae...) (bound-ids a-wae) ; '(x) (binding-ids a-wae) ; '()... we ve found a bug. 5

Property Testing We can test this property in the usual style. ; bound=>binding? : WAE -> boolean (define (bound=>binding? e)...) (test (bound=>binding? (id 'x)) true) (test (bound=>binding? (with 'x (num 0) (id 'x))) true) But the expected result is always true. 6

Automated Property Testing Write a program to generate test inputs! 7

Random WAEs ; random-wae: -> WAE (define (random-wae) (case (random 5) [(0) (num (random-nat))] [(1) (id (random-symbol))] [(2) (add (random-wae) (random-wae))] [(3) (sub (random-wae) (random-wae))] [(4) (with (random-symbol) (random-wae) (random-wae))])) 8

Random WAEs ; random-nat: -> nat (define (random-nat) (case (random 2) [(0) 0] [(1) (add1 (random-nat))])) ; random-symbol: -> symbol (define (random-symbol) (random-elem '(x y z a b c))) ; random-elem: (listof X) -> X (define (random-elem xs) (list-ref xs (random (length xs)))) 9

Generation Strategy To build a WAE, 1/5 of the time, build a number 1/5 of the time, build a symbol 3/5 of the time, first build two more WAEs 10

Expected Progress On average, we reduce the problem from Generate 1 WAE. to Generate 1.2 WAEs. since 1.2 = (2/5)*0 + (3/5)*2 11

Height Bound Limit WAE size by bounding tree height. ; random-wae/b: nat -> WAE (define (random-wae/b h) (case (random (if (zero? h) 2 5)) [(0) (num (random-nat))] [(1) (id (random-symbol))] [(2) (add (random-wae/b (sub1 h)) (random-wae/b (sub1 h)))] [(3) (sub (random-wae/b (sub1 h)) (random-wae/b (sub1 h)))] [(4) (with (random-symbol) (random-wae/b (sub1 h)) (random-wae/b (sub1 h)))])) (Or adjust weights.) 12

Property Implementation ; bound=>binding: WAE -> boolean (define (bound=>binding e) (sublist? (bound-ids e) (binding-ids e))) ; sublist?: (listof X) (listof X) -> boolean ; Expects xs and ys to be sorted and have no dups. (define (sublist? xs ys) (cond [(null? xs) #t] [(null? ys) #f] [(equal? (car xs) (car ys)) (sublist? (cdr xs) (cdr ys))] [else (sublist? xs (cdr ys))])) 13

Running Tests ; test-bound=>binding: nat nat -> (or 'passed WAE) (define (test-bound=>binding size attempts) (if (zero? attempts) 'passed (let ([test-input (random-wae/b size)]) (if (bound=>binding test-input) (test-bound=>binding size (sub1 attempts)) test-input)))) (test-bound=>binding 5 1000) 14

HW2 Test Results We ran random tests on your HW2 submissions. Received 99 submissions Tested 6 properties Found a bug in 53 out of those 99 submissions 15

Interpreter Properties Does not crash Produces same result as another implementation Type checker accurately predicts result (later) Program equivalences hold 16

With Elimination Example For example, we should be able to replace a with with a new function. {with {x {+ 7 2}} {+ x x}} {deffun {f x} {+ x x}} {f {+ 7 2}} 17

With Elimination Rule, an Attempt In general, {... {with {an-id a-wae} another-wae}...} 18

With Elimination Rule, an Attempt In general, {... {with {an-id a-wae} another-wae}...} {deffun {new-id an-id} another-wae} {... {new-id a-wae}...} 19

With Elimination Rule, an Attempt In general, Different free variables! {... {with {an-id a-wae} another-wae}...} {deffun {new-id an-id} another-wae} {... {new-id a-wae}...} 20

Rule Example {with {x {+ 2 7}} {with {y {+ x x}} {+ x y}}} {deffun {f y} {+ x y}} {with {x {+ 2 7}} {f {+ x x}}} 21

Rule Example free {with {x {+ 2 7}} {with {y {+ x x}} {+ x y}}} {deffun {f y} {+ x y}} {with {x {+ 2 7}} {f {+ x x}}} bound 22

With Elimination, Fixed Pass free variables of another-wae as arguments. {... {with {an-id a-wae} another-wae}...} {deffun {new-id an-id id 1...} another-wae} {... {new-id a-wae id 1...}...} where (equal? (free-ids another-wae) (list id 1...)) 23

Rule Example x becomes a parameter of f {with {x {+ 2 7}} {with {y {+ x x}} {+ x y}}} {deffun {f y x} {+ x y}} {with {x {+ 2 7}} {f {+ x x} x}} 24