
SICP练习
文章平均质量分 59
程序员进阶必备!《计算机程序的构造和解释》无疑是史上让我们深入理解函数式程序设计精髓的最佳作品。书中的上百道题目更是让人如醍醐灌顶般得到觉悟。这个专栏的完成预计需要很长的时间,暂时求解出了一百多道题,后续会逐步补充和改进。
nomasp
Android 工程师
展开
-
【SICP练习】152 练习4.8
练习4-8原文Exercise 4.8. “Named let” is a variant of let that has the form (let <var> <bindings> <body>)The and are just as in ordinary let, except that is bound within to a procedure whose body is a原创 2015-04-01 09:53:00 · 5487 阅读 · 0 评论 -
【SICP练习】151 练习4.7
练习4-7原文Exercise 4.7. Let* is similar to let, except that the bindings of the let variables are performed sequentially from left to right, and each binding is made in an environment in which all of the原创 2015-04-01 09:09:56 · 4537 阅读 · 0 评论 -
【SICP练习】150 练习4.6
练习4-6原文Exercise 4.6. Let expressions are derived expressions, because (let (( ) … ( )) ) is equivalent to ((lambda ( … ) ) ) Implement a syntactic transformation let->combination that reduces原创 2015-04-01 08:52:20 · 4515 阅读 · 0 评论 -
【SICP练习】149 练习4.5
练习4-5原文Exercise 4.5. Scheme allows an additional syntax for cond clauses, ( => ). If evaluates to a true value, then is evaluated. Its value must be a procedure of one argument; this procedure is th原创 2015-03-31 17:11:03 · 3438 阅读 · 0 评论 -
【SICP练习】148 练习4.4
练习4-4原文Exercise 4.4. Recall the definitions of the special forms and and or from chapter 1: ● and: The expressions are evaluated from left to right. If any expression evaluates to false, false is原创 2015-03-31 13:19:49 · 3067 阅读 · 0 评论 -
【SICP练习】147 练习4.3
练习4-3原文Exercise 4.3. Rewrite eval so that the dispatch is done in data-directed style. Compare this with the datadirected differentiation procedure of exercise 2.73. (You may use the car of a compound原创 2015-03-29 19:35:50 · 2471 阅读 · 0 评论 -
【SICP练习】146 练习4.2
练习4-2原文Exercise 4.2. Louis Reasoner plans to reorder the cond clauses in eval so that the clause for procedure applications appears before the clause for assignments. He argues that this will make the原创 2015-03-29 19:31:59 · 2379 阅读 · 0 评论 -
【SICP练习】145 练习4.1
练习4-1原文Exercise 4.1. Notice that we cannot tell whether the metacircular evaluator evaluates operands from left to right or from right to left. Its evaluation order is inherited from the underlying Li原创 2015-03-29 16:27:24 · 2979 阅读 · 0 评论 -
【SICP练习】144 练习3.82
练习3-82原文Exercise 3.82. Redo exercise 3.5 on Monte Carlo integration in terms of streams. The stream version of estimate-integral will not have an argument telling how many trials to perform. Instead,原创 2015-03-29 15:38:54 · 3046 阅读 · 0 评论 -
【SICP练习】143 练习3.81
练习3-81原文“random” numbers. Produce a stream formulation of this same generator that operates on an input stream of requests to generate a new random number or to reset the sequence to a specified value原创 2015-03-29 15:31:56 · 2549 阅读 · 0 评论 -
【SICP练习】142 练习3.77
练习3-77原文Exercise 3.77. The integral procedure used above was analogous to the “implicit” definition of the infinite stream of integers in section 3.5.2. Alternatively, we can give a definition of inte原创 2015-03-29 11:45:29 · 1868 阅读 · 0 评论 -
【SICP练习】141 练习3.72
练习3-72原文Exercise 3.72. In a similar way to exercise 3.71 generate a stream of all numbers that can be written as the sum of two squares in three different ways (showing how they can be so written). 代码原创 2015-03-29 11:15:42 · 2093 阅读 · 0 评论 -
【SICP练习】140 练习3.71
练习3-71原文代码(define (Ramanujan s) (define (stream-cadr s) (stream-car (stream-cdr s))) (define (stream-cddr s) (stream-cdr (stream-cdr s))) (let ((scar (stream-car s))原创 2015-03-29 11:10:17 · 2998 阅读 · 0 评论 -
【SICP练习】139 练习3.70
练习3-70原文代码(define (merge-weighted s1 s2 weight) (cond ((stream-null? s1) s2) ((stream-null? s2) s1) (else (let ((cars1 (stream-car s1)) (cars2 (stream-car s2))) (cond (原创 2015-03-29 10:41:16 · 1977 阅读 · 0 评论 -
【SICP练习】138 练习3.69
练习3-69原文代码(define (triples s t u) (cons-stream (list (stream-car s) (stream-car t) (stream-car u)) (interleave (stream-map (lambda (x) (cons (stream-car s)原创 2015-03-29 10:20:34 · 2356 阅读 · 0 评论 -
【SICP练习】137 练习3.68
练习3-68原文Exercise 3.68. Louis Reasoner thinks that building a stream of pairs from three parts is unnecessarily complicated. Instead of separating the pair (S0,T0) from the rest of the pairs in the fir原创 2015-03-29 10:11:25 · 2626 阅读 · 0 评论 -
【SICP练习】136 练习3.67
练习3-67原文Exercise 3.67. Modify the pairs procedure so that (pairs integers integers) will produce the stream of all pairs of integers (i,j) (without the condition i < j). Hint: You will need to mix in原创 2015-03-29 10:04:31 · 2728 阅读 · 0 评论 -
【SICP练习】135 练习3.66
练习3-66原文Exercise 3.66. Examine the stream (pairs integers integers). Can you make any general comments about the order in which the pairs are placed into the stream? For example, about how many pairs原创 2015-03-29 10:01:50 · 3478 阅读 · 0 评论 -
【SICP练习】134 练习3.65
练习3-65原文Exercise 3.65. Use the series ln2 = 1- 1/2 + 1/3 - 1/4 + …… to compute three sequences of approximations to the natural logarithm of 2, in the same way we did above for . How rapidly do the原创 2015-03-28 23:58:17 · 1948 阅读 · 0 评论 -
【SICP练习】133 练习3.64
练习3-64原文Exercise 3.64. Write a procedure stream-limit that takes as arguments a stream and a number (the tolerance). It should examine the stream until it finds two successive elements that differ in原创 2015-03-28 23:52:36 · 1839 阅读 · 0 评论 -
【SICP练习】132 练习3.63
练习3-63原文Exercise 3.63. Louis Reasoner asks why the sqrt-stream procedure was not written in the following more straightforward way, without the local variable guesses:(define (sqrt-stream x) (cons原创 2015-03-28 23:28:32 · 2896 阅读 · 0 评论 -
【SICP练习】131 练习3.62
练习3-62原文Exercise 3.62. Use the results of exercises 3.60 and 3.61 to define a procedure div-series that divides two power series. Div-series should work for any two series, provided that the denominat原创 2015-03-28 22:59:56 · 2036 阅读 · 0 评论 -
【SICP练习】130 练习3.61
练习3-61原文 代码(define (reciprocal-series s) (cons-stream 1 (scale-stream (mul-series (stream-cdr s) (reciprocal-series s))原创 2015-03-28 22:58:34 · 1909 阅读 · 0 评论 -
【SICP练习】129 练习3.60
练习3-60原文Exercise 3.60. With power series represented as streams of coefficients as in exercise 3.59, adding series is implemented by add-streams. Complete the definition of the following procedure for原创 2015-03-28 22:52:40 · 2211 阅读 · 0 评论 -
【SICP练习】128 练习3.59
练习3-59原文 代码a)(define (integrate-series s) (stream-map * (stream-map / ones integers) s))b)(define sine-series (cons-stream 0 (integrate-series cosine-series)))(define cosine-series (con原创 2015-03-28 22:48:16 · 1671 阅读 · 0 评论 -
【SICP练习】127 练习3.58
练习3-58原文Exercise 3.58. Give an interpretation of the stream computed by the following procedure:(define (expand num den radix) (cons-stream (quotient (* num radix) den) (expand (r原创 2015-03-28 22:38:17 · 1954 阅读 · 0 评论 -
【SICP练习】126 练习3.57
练习3-57原文Exercise 3.57. How many additions are performed when we compute the nth Fibonacci number using the definition of fibs based on the add-streams procedure? Show that the number of additions woul原创 2015-03-28 22:28:37 · 1504 阅读 · 0 评论 -
【SICP练习】125 练习3.56
练习3-56原文Exercise 3.56. A famous problem, first raised by R. Hamming, is to enumerate, in ascending order with no repetitions, all positive integers with no prime factors other than 2, 3, or 5. One obv原创 2015-03-28 22:18:08 · 1654 阅读 · 0 评论 -
【SICP练习】124 练习3.55
练习3-55原文Exercise 3.55. Define a procedure partial-sums that takes as argument a stream S and returns the stream whose elements are S0, S0 + S1, S0 + S1 + S2, …. For example, (partial-sums integers) sh原创 2015-03-28 22:11:47 · 1264 阅读 · 0 评论 -
【SICP练习】123 练习3.54
练习3-54原文Exercise 3.54. Define a procedure mul-streams, analogous to add-streams, that produces the elementwise product of its two input streams. Use this together with the stream of integers to comple原创 2015-03-28 22:09:54 · 1456 阅读 · 0 评论 -
【SICP练习】122 练习3.53
练习3-53原文Exercise 3.53. Without running the program, describe the elements of the stream defined by (define s (cons-stream 1 (add-streams s s)))分析s是一串2的幂。也就是1、2、4、8、16、32……原创 2015-03-28 22:05:47 · 2218 阅读 · 0 评论 -
【SICP练习】121 练习3.52
练习3-52原文Exercise 3.52. Consider the sequence of expressions(define sum 0) (define (accum x) (set! sum (+ x sum)) sum) (define seq (stream-map accum (stream-enumerate-interval 1 20)))(define y原创 2015-03-28 21:55:08 · 2542 阅读 · 0 评论 -
【SICP练习】120 练习3.51
练习3-51原文Exercise 3.51. In order to take a closer look at delayed evaluation, we will use the following procedure, which simply returns its argument after printing it:(define (show x) (display-line原创 2015-03-28 21:50:11 · 2220 阅读 · 0 评论 -
【SICP练习】119 练习3.50
练习3-50原文Exercise 3.50. Complete the following definition, which generalizes stream-map to allow procedures that take multiple arguments, analogous to map in section 2.2.3, footnote 12. (define (stream原创 2015-03-28 21:44:40 · 2564 阅读 · 0 评论 -
【SICP练习】118 练习3.45【待完成】
练习3-45原文Exercise 3.45. Louis Reasoner thinks our bank-account system is unnecessarily complex and error-prone now that deposits and withdrawals aren’t automatically serialized. He suggests that原创 2015-03-26 20:02:29 · 2067 阅读 · 0 评论 -
【SICP练习】117 练习3.44
练习3-43原文Exercise 3.44. Consider the problem of transferring an amount from one account to another. Ben Bitdiddle claims that this can be accomplished with the following procedure, even if there are mu原创 2015-03-26 19:59:00 · 2540 阅读 · 0 评论 -
【SICP练习】116 练习3.42
练习3-42原文Exercise 3.42. Ben Bitdiddle suggests that it’s a waste of time to create a new serialized procedure in response to every withdraw and deposit message. He says that make-account could be chang原创 2015-03-26 19:43:42 · 2787 阅读 · 0 评论 -
【SICP练习】115 练习3.41
练习3-41原文Exercise 3.41. Ben Bitdiddle worries that it would be better to implement the bank account as follows (where the commented line has been changed):(define (make-account balance) (define (wi原创 2015-03-26 19:32:12 · 2657 阅读 · 0 评论 -
【SICP练习】114 练习3.38-3.39
练习3-38原文Exercise 3.38. Suppose that Peter, Paul, and Mary share a joint bank account that initially contains 100.Concurrently,Peterdeposits100. Concurrently, Peter deposits 10, Paul withdraws $20, and原创 2015-03-26 14:35:09 · 3588 阅读 · 0 评论 -
【SICP练习】113 练习3.33
练习3-33原文Exercise 3.33. Using primitive multiplier, adder, and constant constraints, define a procedure averager that takes three connectors a, b, and c as inputs and establishes the constraint that th原创 2015-03-26 12:50:21 · 2394 阅读 · 0 评论