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
// mirror... | |
func cons<T0, T1>(_ x: T0, _ y: T1) -> (T0, T1) { | |
return (x, y) | |
} | |
func car<T0, T1>(_ t:(T0, T1)) -> T0 { | |
return t.0 | |
} | |
func cdr<T0, T1>(_ t:(T0, T1)) -> T1 { |
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 (iterative-improve good-enough? impove) | |
(define (f x) | |
(if (good-enough? x) | |
x | |
(f (impove x)) | |
) | |
) | |
f | |
) |
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 (png-size w h) (* w h 4.0 1/1024)) |
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 (newton-transform g) | |
(lambda (x) | |
(- x (/ (g x) ((deriv g) x))))) | |
(define (deriv g) | |
(lambda (x) | |
(/ (- (g (+ x dx)) (g x)) | |
dx) | |
) | |
) |
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 (cont-frac-full n d k calculator) | |
(define (iterator i) | |
(if (< i k) | |
(/ (n i) (calculator (d i) (iterator (+ i 1)))) | |
(/ (n i) (d i)) | |
) | |
) |
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 (filtered-accumulate combiner null-value term a next b filter?) | |
(if (> a b) | |
null-value | |
(combiner (if (filter? a) (term a) null-value) | |
(filtered-accumulate combiner null-value term (next a) next b filter?) | |
) | |
) | |
) | |
(define (filtered-sum term a next b filter?) |
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 combiner null-value term a next b) | |
(if (> a b) | |
null-value | |
(combiner (term a) | |
(accumulate combiner null-value term (next a) next b) | |
) | |
) | |
) | |
(define (accumulate combiner null-value term a next b) |
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 (product term a next b) | |
(if (> a b) | |
1 | |
(* (term a) | |
(product term (next a) next b) | |
) | |
) | |
) | |
(define (product term a next b) |
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 (sum term a next b) | |
(if (> a b) | |
0 | |
(+ (term a) | |
(sum term (next a) next b) | |
) | |
) | |
) | |
; 求立方. |
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 (sum term a next b) | |
(if (> a b) | |
0 | |
(+ (term a) | |
(sum term (next a) next b) | |
) | |
) | |
) | |
; 结果逼近 Π/8 |