Form over Function
Teaching Beginners How to Construct Programs Michael Sperber Collaborators: Marcus Crestani, Martin Gasbichler, Herbert Klaeren, Eric Knauel @ University of Tübingen
Wednesday, September 12, 12
Form over Function Teaching Beginners How to Construct Programs - - PowerPoint PPT Presentation
Form over Function Teaching Beginners How to Construct Programs Michael Sperber Collaborators: Marcus Crestani, Martin Gasbichler, Herbert Klaeren, Eric Knauel @ University of Tbingen Wednesday, September 12, 12 Back at the Ranch ...
Form over Function
Teaching Beginners How to Construct Programs Michael Sperber Collaborators: Marcus Crestani, Martin Gasbichler, Herbert Klaeren, Eric Knauel @ University of Tübingen
Wednesday, September 12, 12Back at the Ranch ...
Wednesday, September 12, 12Volker Claus’s Trick
Wednesday, September 12, 12So How Is This About Scheme?
Wednesday, September 12, 12Self-Deception
Scheme Is Great For Beginners
Wednesday, September 12, 12Scheme Is Great For Beginners
What Is Important to You?
Wednesday, September 12, 12Geometric Shapes
A geometric shape is one of the following:
Geometric Shapes
Implement geometric shapes! Write a program that allows creating geometric shapes und to check whether a given point is inside our outside a geometric shape!
Wednesday, September 12, 12Geometric Shapes
Shape Square Circle Overlay
Wednesday, September 12, 12Design Recipes
Page from English 6
Wednesday, September 12, 12Data Analysis
Mixed Data
A geometric shape is one of the following:
Composite Data
A circle has:
Design Recipe
“When your data analysis contains composite data, identify the signatures of the
starting with the following:
; An x consists of / has: ; - field1 (sig1) ; ... ; - fieldn (sign)
Wednesday, September 12, 12Design Recipe
Then translate the data definition into a record definition:
(define-record-procedures sig constr pred? (select1 ... selectn)
Wednesday, September 12, 12Design Recipe
Also write a constructor signature of the following form:
(: constr (sig1 ... sign -> sig))
Also, write signatures for the predicate and the selectors:
(: pred? (any -> boolean)) (: select1 (sig -> sig1)) ... (: selectn (sig -> sign))
Wednesday, September 12, 12Circles
; A circle consists of: ; - center (point) ; - radius (real) (define-record-procedures circle make-circle circle? (circle-center circle-radius)) (: make-circle (point real -> circle)) (: circle? (any -> boolean)) (: circle-center (circle -> point)) (: circle-radius (circle -> real))
Wednesday, September 12, 12Composite Data
A square consists of:
Squares
; A square consists of: ; - lower left corner (point) ; - size / edge length (real) (define-record-procedures square make-square square? (square-corner square-size)) (: make-square (point real -> square)) (: square? (any -> boolean)) (: square-corner (square -> point)) (: square-size (square -> real))
Wednesday, September 12, 12Composite Data with Self Reference
On overlay consists of:
Overlays
; An overlay consists of: ; - a geometric shape “on top” (shape) ; - a geometric shape “on bottom” (shape) (define-record-procedures overlay make-overlay overlay? (overlay-top-shape overlay-bot-shape)) (: make-overlay (shape shape -> overlay)) (: overlay? (any -> boolean)) (: overlay-top-shape (overlay -> shape)) (: overlay-bot-shape (overlay -> shape))
Wednesday, September 12, 12Points
; A point consists of: ; - x coordinate (real) ; - y coordinate (real) (define-record-procedures point make-point point? (point-x point-y)) (: make-point (real real -> point)) (: point? (any -> boolean)) (: point-x (point -> real)) (: point-y (point -> real))
Wednesday, September 12, 12Geometric Shapes
; A geometric shape is one of the following: ; - a circle (circle) ; - a square parallel to the axes (square) ; - on overlay of two geometric figures (overlay) (define shape (signature (mixed circle square
Examples
Wednesday, September 12, 12Examples
(define p1 (make-point 10 20)) ; Point at X=10, Y=20 (define p2 (make-point 30 50)) ; Point at X=30, Y=50 (define p3 (make-point 40 30)) ; Point at X=40, Y=30 (define s1 (make-square p1 40)) ; Square w/ corner at p1, size 40 (define c1 (make-circle p2 20)) ; Circle around p2, radius 20 (define o1 (make-overlay c1 s1)) ; Overlay of circle und square (define c2 (make-circle p3 15)) ; Circle around p3, radius 10 (define o2 (make-overlay o1 c2)) ; Overlay of o1 and c2
Wednesday, September 12, 12First Steps
; is a point within a shape? (: point-in-shape? (point shape -> boolean)) (check-expect (point-in-shape? p2 c1) #t) (check-expect (point-in-shape? p3 c2) #t) (check-expect (point-in-shape? (make-point 51 50) c1) #f) (check-expect (point-in-shape? (make-point 11 21) s1) #t) (check-expect (point-in-shape? (make-point 49 59) s1) #t) (check-expect (point-in-shape? (make-point 9 21) s1) #f) (check-expect (point-in-shape? (make-point 11 19) s1) #f) (check-expect (point-in-shape? (make-point 51 59) s1) #f) (check-expect (point-in-shape? (make-point 49 61) s1) #f) (check-expect (point-in-shape? (make-point 40 30) o2) #t) (check-expect (point-in-shape? (make-point 0 0) o2) #f)
short description signature examples
Wednesday, September 12, 12Template
(define point-in-shape? (lambda (p s) ...))
Wednesday, September 12, 12Skeleton
(define point-in-shape? (lambda (p s) ... p ... s ... ... (point-x p) ... (point-y p) ... (cond ((circle? s) ...) ((square? s) ...) ((overlay? s) ...))))
Wednesday, September 12, 12More Skeleton
(define point-in-shape? (lambda (p s) ... p ... s ... ... (point-x p) ... (point-y p) ... (cond ((circle? s) ... (circle-center s) ... (circle-radius s) ...) ((square? s) ... (square-corner s) ... (square-size s) ...) ((overlay? s) ... (overlay-top-shape s) ... (overlay-bot-shape s) ...))))
Wednesday, September 12, 12More Skeleton
(define point-in-shape? (lambda (p s) ... p ... s ... ... (point-x p) ... (point-y p) ... (cond ((circle? s) ... (circle-center s) ... (circle-radius s) ...) ((square? s) ... (square-corner s) ... (square-size s) ...) ((overlay? s) ... (point-in-shape? p (overlay-top-shape s)) ... (point-in-shape? p (overlay-bot-shape s)) ...))))
Wednesday, September 12, 12Definition
(define point-in-shape? (lambda (p s) (cond ((circle? s) (<= (distance p (circle-center s)) (circle-radius s))) ((square? s) (and (>= (point-x p) (point-x (square-corner s))) (<= (point-x p) (+ (point-x (square-corner s)) (square-size s))) (>= (point-y p) (point-y (square-corner s))) (<= (point-y p) (+ (point-y (square-corner s)) (square-size s))))) ((overlay? s) (or (point-in-shape? p (overlay-top-shape s))
Wednesday, September 12, 12Refinement
(define point-in-shape? (lambda (p s) (cond ((circle? s) (<= (distance p (circle-center s)) (circle-radius s))) ((square? s) (let ((corner (square-corner s))) (let ((cx (point-x corner)) (cy (point-y corner)) (size (square-size s)) (x (point-x p)) (y (point-y p))) (and (>= x cx) (<= x (+ cx size)) (>= y cy) (<= y (+ cy size)))))) ((overlay? s) (or (point-in-shape? p (overlay-top-shape s)) (point-in-shape? p (overlay-bot-shape s)))))))
Wednesday, September 12, 12Enforcement
Wednesday, September 12, 12Enforcement
Wednesday, September 12, 12Enforcement
Wednesday, September 12, 12Measure
Wednesday, September 12, 12Observe & Measure
Wednesday, September 12, 12Form
Wednesday, September 12, 12How Many Forms?
Wednesday, September 12, 12How Many Forms?
Wednesday, September 12, 12Scheme
... is our business!
Wednesday, September 12, 12Practice
Wednesday, September 12, 12So Why Again Is Scheme Important?
Wednesday, September 12, 12Signature violations
Wednesday, September 12, 12Properties
(check-property (for-all ((a number) (b number)) (= (+ a b) (+ b a))))
Wednesday, September 12, 12Properties
(: commutativity ((%a %a -> %b) signature -> property)) (define commutativity (lambda (op sig) (for-all ((a sig) (b sig)) (expect (op a b) (op b a)))))
Wednesday, September 12, 12Images
Wednesday, September 12, 12Why Not Start With Types?
data Tool1 = ... data ToolState1 = ... data Tool2 = ... data ToolState2 = ... data Tool = Tool1 | Tool2 data ToolState = ToolState1 | ToolState2
Wednesday, September 12, 12Summary
Collaboration Record
Wednesday, September 12, 12