1 / 10

GBK Programming 1

GBK Programming 1. Jordan Johnson. Today’s plan. Greeting Review cond Lesson : movement in two dimensions Homework Clean-up. Cond -expressions. ( cond …). Problem.

GBK Programming 1

E N D

Presentation Transcript

1. GBK Programming 1 Jordan Johnson

2. Today’s plan Greeting Review cond Lesson: movement in two dimensions Homework Clean-up

3. Cond-expressions (cond …)

4. Problem Develop the function sign that takes a number and returns its sign (-1 for negative numbers, 1 for positive numbers, 0 for 0).

5. Problem (define W 200) (define H 300) Suppose we’rewriting pong: Develop the function ball-state that takes the ball’s x-coordinate and returns “play” if the ball is onscreen, “L” if the ball has gone off the left side, “R” if it’s gone off the right side.

6. Movement in 2-D • So far, our worlds are simple: • a number • a string • Pong requires 2 dimensions… • …and for that we need posns.

7. posns: points in 2-space • A posn is a (make-posnnumbernumber)where the numbers together represent an x- and y-coordinate pair. • e.g., (3, 7) would be (make-posn3 7) • Laws of posns: • (posn-x (make-posna b))  a • (posn-y (make-posna b))  b

8. posn functions make-posn is the posnconstructor. posn-x and posn-y are accessors or selectors. We also get posn?, which is a type predicate.

9. Homework • Due Wednesday: HW on cond. • See web site.

10. Clean-up • Before you leave, please . . . • Log out. • Push in your chair. • Make sure you’ve got everything. • Make sure all trash ends up in the trash can.

More Related