notes18 - version In file...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 61A Lecture Notes Week 4 Topic: Data abstraction, sequences Reading: Note: The frst midterm is next week. Big ideas: data abstraction, abstraction barrier. IF we are dealing with some particular type oF data, we want to talk about it in terms oF its meaning , not in terms oF how it happens to be represented in the computer. Example: Here is a Function that computes the total point score oF a hand oF playing cards. (This simplifed Function ignores the problem oF cards whose rank-name isn’t a number.) ;;;;; In file cs61a/lectures/2.1/total.scm (define (total hand) (if (empty? hand) 0 (+ (butlast (last hand)) (total (butlast hand)) ))) > (total ’(3h 10c 4d)) 17 This Function calls butlast in two places. What do those two invocations mean? Compare it with a modifed
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: version: ;;;;; In file cs61a/lectures/2.1/total.scm (define (total hand) (if (empty? hand) (+ (rank (one-card hand)) (total (remaining-cards hand)) ))) (define rank butlast) (define suit last) (define one-card last) (define remaining-cards butlast) This is more work to type in, but the result is much more readable. IF For some reason we wanted to modiFy the program to add up the cards leFt to right instead oF right to leFt, we’d have trouble editing the original version because we wouldn’t know which butlast to change. In the new version it’s easy to keep track oF which Function does what. The auxiliary Functions like rank are called selectors because they select one component oF a multi-part datum. 284...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online