SICP

it2024-11-13  16

1 #lang sicp 2 3 (#%require sicp-pict) 4 5 6 ;;;;;;;;;;;;;;;;;;2.44 7 (define (up-split painter n) 8 (if (= n 0) 9 painter 10 (let ((smaller (up-split painter (- n 1)))) 11 (below painter (beside smaller smaller))))) 12 13 ;;;;;;;;;;;;;;;;;test 14 (paint (up-split einstein 4)) 15 16 ;;;;;;;;;;;;;;;;;;2.45 17 18 (define (split op1 op2) 19 (lambda (painter n) 20 (if (= n 0) 21 painter 22 (let ((smaller ((split op1 op2) painter (- n 1)))) 23 (op1 painter (op2 smaller smaller)))))) 24 25 ;(define (split op1 op2) 26 ; (define (inner pinter n) 27 ; (if (= n 0) 28 ; painter 29 ; (let ((smaller (inner painter (- n 1)))) 30 ; (op1 painter (op2 smaller smaller))))) 31 ; inner) 32 33 (define right-split (split beside below)) 34 ;;;;;;;;;;;;;;;;;test 35 (paint (right-split einstein 4)) 36 37 ;;;;;;;;;;;;;;;;;;;2.46 38 (define (make-vect a b) 39 (cons a b)) 40 41 (define (xcor-vect v) 42 (car v)) 43 44 (define (ycor-vect v) 45 (cdr v)) 46 47 (define (add-vect v1 v2) 48 (make-vect (+ (xcor-vect v1) 49 (xcor-vect v2)) 50 (+ (ycor-vect v1) 51 (ycor-vect v2)))) 52 53 (define (sub-vect v1 v2) 54 (make-vect (- (xcor-vect v1) 55 (xcor-vect v2)) 56 (- (ycor-vect v1) 57 (ycor-vect v2)))) 58 59 (define (scale-vect s v1) 60 (make-vect (* s (xcor-vect v1)) 61 (* s (ycor-vect v1)))) 62 63 ;;;;;;;;;;;;;;;;;;;;2.47 64 (define (make-frame1 origin edge1 edge2) 65 (list origin edge1 edge2)) 66 67 (define (make-frame2 origin edge1 edge2) 68 (cons origin (cons edge1 edge2))) 69 70 ;;;;;;;;;;;;;;;1 71 (define (origin-frame1 frame) 72 (car frame)) 73 74 (define (edge1-frame1 frame) 75 (cadr frame)) 76 77 (define (edge2-frame1 frame) 78 (caddr frame)) 79 80 ;;;;;;;;;;;;;;;2 81 (define (origin-frame2 frame) 82 (car frame)) 83 84 (define (edge1-frame2 frame) 85 (cadr frame)) 86 87 (define (edge2-frame2 frame) 88 (cddr frame))

 

转载于:https://www.cnblogs.com/tclan126/p/6424906.html

最新回复(0)