{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# notes23 - y rectangle 2 The direction of arrows(up down...

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

To give you a better idea about what a sentence is, here’s a version of the constructor function: ;;;;; In file cs61a/lectures/2.2/sentence.scm (define (se a b) (cond ((word? a) (se (list a) b)) ((word? b) (se a (list b))) (else (append a b)) )) (define (word? x) (or (symbol? x) (number? x)) ) Se is a lot like append , except that the latter behaves oddly if given words as arguments. Se can accept words or sentences as arguments. Box and pointer diagrams. Here are a few details that people sometimes get wrong about them: 1. An arrow can’t point to half of a pair. If an arrowhead touches a pair, it’s pointing to the entire pair, and it doesn’t matter exactly where the arrowhead touches the rectangle. If you see something like (define x (car y)) where y is a pair, the arrow for x should point to the thing that the car of y points to , not to the left half of the
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: y rectangle. 2. The direction of arrows (up, down, left, right) is irrelevant. You can draw them however you want to make the arrangement of pairs neat. That’s why it’s crucial not to forget the arrowheads! 3. There must be a top-level arrow to show where the structure you’re representing begins. How do you draw a diagram for a complicated list? Take this example: ((a b) c (d (e f))) You begin by asking yourself how many elements the list has. In this case it has three elements: Frst (a b) , then c , then the rest. Therefore you should draw a three-pair backbone : three pairs with the cdr of one pointing to the next one. (The Fnal cdr is null.) Only after you’ve drawn the backbone should you worry about making the car s of your three pairs point to the three elements of the top-level list. 289...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online