Hailperin, Chapter 1 Slides, Intro Course. Slide, Demo Scheme. > 13 > -4 > 2/3 > .666 > 4/6 > 2+3 error > (+ 2 3) > (sqrt 16) > sqrt > + > 2+3i > (sqrt 2+3i) > -7 > (- 7) > (- -7) various nested expressions > (define myPi 3.1415962) > myPi > (/ 22 7) > (/ 22 7.) > (define myPi (/ 22 7.)) > myPi > sqrt > (sqrt 25) > (square 5) error > (* 5 5) > (lambda (x) (* x x)) > ((lambda (x) (* x x)) 5) Slide, Lambda expression, Function Slide, Lambda expression, Parameter list Class exercise: Write a function that returns the area of a circle of radius r, then apply it to a circle with radius 13. Naming functions Class exercise: Write a function that names the function square. > (define square (lambda (x) (* x x))) > (square 5) Class exercise: Write a function that names the function area. > (define area (lambda (r) (* myPi (square r)))) > (area 13) Demo defining in the editor pane with the Run button. > (< 2 3) > (> 2 3) > #t > #f > (if #t 5 7) > (if #f 5 7) > (abs -7) Class exercise: Write a function myabs that returns the absolute value of a number. (define myabs (lambda (x) (if (< x 0) (- x) x))) Quilting - see Setup for Scheme Note the following two steps. 1. Install concabs.plt. Only required once. 2. Copy and paste quilt.txt into editor window. Required each time. Demo > rcross-bb > corner-bb > test-bb > nova-bb > (stack rcross-bb corner-bb) > test-bb > (quarter-turn-right test-bb) Predict > (quarter-turn-right (stack test-bb test-bb)) > (stack (quarter-turn-right test-bb) test-bb) > (stack (quarter-turn-right test-bb) test-bb) Class exercise: Create the pattern from the slide: Quilt pattern > (stack (quarter-turn-right (stack rcross-bb rcross-bb)) (quarter-turn-right (stack rcross-bb rcross-bb)))