This preview shows page 1. Sign up to view the full content.
Unformatted text preview: deep-map to look more like a binary tree program: ;;;;; In file cs61a/lectures/2.2/tree3.scm (define (deep-map fn xmas) (cond ((null? xmas) ()) ((pair? xmas) (cons (deep-map fn (car xmas)) (deep-map fn (cdr xmas)))) (else (fn xmas)))) (The Formal parameter xmas reects the Fact that the picture looks kind oF like a Christmas tree.) This procedure strongly violates data abstraction! Ordinarily when dealing with lists, we write programs that treat the car and the cdr dierently, reecting the Fact that the car oF a pair is a list element, whereas the cdr is a sublist. But here we treat the car and the cdr identically. One advantage oF this approach is that it works even For improper lists: > (deep-map square ((3 . 4) (5 6)) ((9 . 16) (25 36)) 302...
View Full Document
This note was uploaded on 02/17/2010 for the course COMPUTER S 26275 taught by Professor Harvey,b during the Spring '10 term at University of California, Berkeley.
- Spring '10