50 likes | 151 Vues
Syntactic Note. Scheme excerpts in the The Schemer’s Guide have a slightly different syntax, for example: (cond [(null? A) ▿empty) [(null? B) (cons b ▿())] [else ▿full]). Syntactic Note. (cond [(null? A) ▿empty) [(null? B) (cons b ▿())]
E N D
Syntactic Note • Scheme excerpts in the The Schemer’s Guide have a slightly different syntax, for example: (cond [(null? A) ▿empty) [(null? B) (cons b ▿())] [else ▿full]) 0704.315 - Programming Languages
Syntactic Note (cond [(null? A) ▿empty) [(null? B) (cons b ▿())] [else ▿full]) becomes (cond ((null? A) 'empty) ((null? B) (cons b '())) (else 'full)) 0704.315 - Programming Languages
car/cdr vs. first/rest (define a (list 1 2 3 4)) • In Schemer’s Guide: (first a) 1 (rest a) '(2 3 4) • In Scheme48: (car a) 1 (cdr a) '(2 3 4) 0704.315 - Programming Languages
car/cdr vs. first/rest • First/rest are synonymous with car/cdr (define first car) (define rest cdr) 0704.315 - Programming Languages
List Processing • Think of the list data structure as a sequence of values (define first-4-integers (list 1 2 3 4)) • We can write functions that operate on sequences: • sum, product, average • Increment-each, square-each 0704.315 - Programming Languages