This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (for-each1 func items) | |
| (cond ((null? items) | |
| ()) | |
| (else (func (car items)) (for-each1 func (cdr items)))) | |
| ) | |
| (for-each (lambda (x) (newline) (display x)) | |
| (list 57 321 88)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (car (cdaddr (list 1 3 (list 5 7) 9))) | |
| (caar (list ( list 7))) | |
| (caddr (cddddr (cons 1 (cons 2 (cons 3 (cons 4 (cons 5 (list 6 7)))))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define x (list 1 2 3)) | |
| (define y (list 4 5 6)) | |
| (append x y) | |
| (cons x y) | |
| (list x y) | |
| => | |
| (1 2 3 4 5 6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (atom? x) (not (pair? x))) | |
| (define (deep-reverse l) | |
| (cond ((null? l) l) | |
| ((atom? (car l))(append (deep-reverse (cdr l)) (list (car l)))) | |
| (else (append (deep-reverse (cdr l)) (list(deep-reverse (car l))))) | |
| ) | |
| ) | |
| (deep-reverse (list 1 4 9 (list 2 3 4) 16 25)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (atom? x) (not (pair? x))) | |
| (define (deep-reverse l) | |
| (cond ((null? l) l) | |
| ((atom? (car l))(append (deep-reverse (cdr l)) (list (car l)))) | |
| (else (append (deep-reverse (cdr l)) (deep-reverse (car l)))) | |
| ) | |
| ) | |
| (deep-reverse (list 1 4 9 (list 2 3 4) 16 25)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (atom? x) (not (pair? x))) | |
| (define (square x) (* x x)) | |
| (define (square-tree items) | |
| (cond ((null? items) '()) | |
| ((atom? (car items)) | |
| ( cons (* (car items) (car items)) (square-tree (cdr items)))) | |
| (else ( cons (square-tree (car items)) (square-tree (cdr items)))))) | |
| (define (map-square-tree x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (atom? x) (not (pair? x))) | |
| (define (square x) (* x x)) | |
| (define (tree-map func items) | |
| (cond ((null? items) '()) | |
| ((atom? (car items)) | |
| ( cons (func (car items)) (square-tree (cdr items)))) | |
| (else ( cons (square-tree (car items)) (square-tree (cdr items)))))) | |
| (define (tree-map2 func x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (subsets s) | |
| (if (null? s) | |
| (list ()) | |
| (let ((rest (subsets (cdr s)))) | |
| (append rest (map (lambda (x) (cons (car s) x)) | |
| rest))))) | |
| (subsets (list 1 2 3 )) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (accumulate op initial sequence) | |
| (if (null? sequence) | |
| initial | |
| (op (car sequence) | |
| (accumulate op initial (cdr sequence))))) | |
| (define (square x) (* x x)) | |
| (define (map p sequence) | |
| (accumulate (lambda (x y) (cons (p x) y)) () sequence)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define (accumulate op initial sequence) | |
| (if (null? sequence) | |
| initial | |
| (op (car sequence) | |
| (accumulate op initial (cdr sequence))))) | |
| (define (horner-eval x coefficient-sequence) | |
| (accumulate (lambda (this-coeff higher-terms) | |
| (+ (* x higher-terms) this-coeff)) |