form over function
play

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 ...


  1. 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

  2. Back at the Ranch ... Wednesday, September 12, 12

  3. Volker Claus’s Trick Wednesday, September 12, 12

  4. Wednesday, September 12, 12

  5. Wednesday, September 12, 12

  6. Wednesday, September 12, 12

  7. So How Is This About Scheme? Wednesday, September 12, 12

  8. U ? Wednesday, September 12, 12

  9. Self-Deception • plagiarism • stronger students are more vocal • strong students teach themselves Wednesday, September 12, 12

  10. Scheme Is Great For Beginners • Syntax • Size • Functional • Easy to transition to X Wednesday, September 12, 12

  11. Scheme Is Great For Beginners Wrong • Syntax • Size • Functional Questions! • Easy to transition to X Wednesday, September 12, 12

  12. What Is Important to You? Wednesday, September 12, 12

  13. Geometric Shapes A geometric shape is one of the following: • square (parallel to axes) • circle • overlay of 2 geometric shapes Wednesday, September 12, 12

  14. 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, 12

  15. Geometric Shapes Shape Square Circle Overlay Wednesday, September 12, 12

  16. Design Recipes Page from English 6 Wednesday, September 12, 12

  17. U ? Wednesday, September 12, 12

  18. Data Analysis • shapes • squares • circles • overlays • points • (2-dimensional plane) Wednesday, September 12, 12

  19. Mixed Data A geometric shape is one of the following: • a circle • a square • an overlay Wednesday, September 12, 12

  20. Composite Data A circle has: • center • radius Wednesday, September 12, 12

  21. Design Recipe “When your data analysis contains composite data, identify the signatures of the components. Then write a data definition starting with the following: ; An x consists of / has: ; - field 1 (sig 1 ) ; ... ; - field n (sig n ) Wednesday, September 12, 12

  22. Design Recipe Then translate the data definition into a record definition: (define-record-procedures sig constr pred? (select 1 ... select n ) Wednesday, September 12, 12

  23. Design Recipe Also write a constructor signature of the following form: (: constr (sig 1 ... sig n -> sig)) Also, write signatures for the predicate and the selectors: (: pred? (any -> boolean)) (: select 1 (sig -> sig 1 )) ... (: select n (sig -> sig n )) Wednesday, September 12, 12

  24. Circles ; 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, 12

  25. Composite Data A square consists of: • lower left corner • size Wednesday, September 12, 12

  26. 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, 12

  27. Composite Data with Self Reference On overlay consists of: • a geometric shape • and another geometric shape Wednesday, September 12, 12

  28. 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, 12

  29. Points ; 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, 12

  30. Geometric 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 overlay))) Wednesday, September 12, 12

  31. Examples Wednesday, September 12, 12

  32. Examples (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, 12

  33. First Steps short description ; is a point within a shape? (: point-in-shape? (point shape -> boolean)) signature (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) examples Wednesday, September 12, 12

  34. Template (define point-in-shape? (lambda (p s) ...)) Wednesday, September 12, 12

  35. Skeleton (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, 12

  36. More 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, 12

  37. More 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, 12

  38. Definition (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, 12

  39. Refinement (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, 12

  40. Enforcement Wednesday, September 12, 12

  41. Enforcement Wednesday, September 12, 12

  42. Enforcement Wednesday, September 12, 12

  43. U ? Wednesday, September 12, 12

  44. Measure Wednesday, September 12, 12

  45. Observe & Measure Wednesday, September 12, 12

  46. Form Wednesday, September 12, 12

  47. How Many Forms? Wednesday, September 12, 12

  48. How Many Forms? Wednesday, September 12, 12

  49. Scheme ... is our business! Wednesday, September 12, 12

  50. Practice Wednesday, September 12, 12

  51. So Why Again Is Scheme Important? Wednesday, September 12, 12

  52. Signature violations Wednesday, September 12, 12

  53. Properties (check-property (for-all ((a number) (b number)) (= (+ a b) (+ b a)))) Wednesday, September 12, 12

  54. Properties (: 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, 12

  55. Images Wednesday, September 12, 12

  56. Why Not Start With Types? data Tool1 = ... data ToolState1 = ... data Tool2 = ... data ToolState2 = ... data Tool = Tool1 | Tool2 data ToolState = ToolState1 | ToolState2 Wednesday, September 12, 12

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend