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.

helene
Download Presentation

GBK Programming 1

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

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