sicp

Use mit-scheme with REPL and editor together

拈花ヽ惹草 提交于 2021-02-10 20:12:10
问题 I'm going through SICP course and as recommended installed mit-scheme. I want to use the REPL together with a scheme file. The reason is because I can add scheme code in the file and then run the commands in REPL. What I have works, but the problem is every time I edit the file, I have to quit terminal and reload the file for REPL to see changes. Is there a way to reload the file easily or some other way for REPL to see changes from the file? This my setup: I installed mit-scheme with brew

【SICP练习】87 练习2.59

℡╲_俬逩灬. 提交于 2021-02-06 07:46:14
练习2.59 我们可以采用迭代来完成这个过程,至于怎么迭代的,接下来就是代码了。 ( define ( union-set set1 set2) ( define ( union-set-iter set1 set2) ( if ( null? input) ( reverse result) ( let ( ( current-element ( car input) ) ( remain-element ( cdr input) ) ( if ( element-of-set? current-element result) ( union-set-iter remain-element result) ( union-set-iter remain-element ( cons current-element result) ) ) ) ) ) ( union-set-iter ( append set1 set2) ‘ () ) ) 感谢访问,希望对您有所帮助。 欢迎关注或收藏、评论或点赞。 为使本文得到斧正和提问,转载请注明出处: http://blog.csdn.net/nomasp 版权声明:本文为 NoMasp柯于旺 原创文章,未经许可严禁转载!欢迎访问我的博客:http://blog.csdn.net/nomasp 来源: oschina 链接: https:/

【SICP练习】59 练习2.29

回眸只為那壹抹淺笑 提交于 2021-02-06 01:26:59
 练习 2.29 这种题,还有之前的那个 rectangle 的题目,对于变量、函数等的命名简直要让人疯掉。先来写出题目中的 left-branch 和 right-branch 吧。 (define (left-branch mobile) (car mobile)) (define (right-branch mobile) (cadr mobile)) 注意这里是 cadr 而不是 cdr 。对应的 branch-length 和 branch-structure 。 (define (branch-length branch) (car branch)) (define (branch-structure branch) (cadr branch)) a 小题并不难, b 小题中的 total-weight 也就是要求每部分 branch-structure 。而根据题目的意思,如果一个分支吊着另一个活动体,那么这个活动体的重量就是这个分支的重量,否则分支的 structure 就是这个分支的重量。而判断这个分支是不是还有其他活动体我们可以用 pair? 来判断。而总重量就是左右两部分的重量之和。 (define (branch-weight branch) (if (pair? (branch-structure branch)) (total-weight

Why does this return a list '(5) rather than the number 5?

放肆的年华 提交于 2021-01-28 12:01:02
问题 I am working through SICP, and the exercise I am working on asks for a procedure that returns the last element in a list. I implemented the procedure last-pair to do this, but I'm confused why it's returning a list rather than a number: (define (last-pair alist) (cond ((null? (cdr alist)) (car alist)) ; still happens if this is just "car alist)" (else (last-pair (cdr alist))))) When I invoke it on a list of the integers from 1 to 5, I get the output '(5): > (last-pair (list 1 2 3 4 5)) '(5) I

SICP 2.30 2.31 2.32

邮差的信 提交于 2020-02-28 17:19:36
2.30 (define (square-tree tree) (cond ((null? tree) '()) ((pair? tree) (cons (square-tree (car tree)) (square-tree (cdr tree)))) (else (* tree tree)))) (define (map-square-tree tree) (map (lambda (sub-tree) (if (pair? sub-tree) (map-square-tree sub-tree) (* sub-tree sub-tree))) tree)) 2.31 (define (tree-map f tree) (map (lambda (sub-tree) (if (pair? sub-tree) (tree-map f sub-tree) (f sub-tree))) tree)) 2.32 这道题的解题方法步骤是猜想、验证、解释。 猜想:以(subsets (list 3))代入,得出两个答案 (lambda (x) (append s x)) (lambda (x) (cons (car s) x)) 验证:以(subset (list 1 2 3))代入进行验证,得出猜想的第二个答案是正确的 解释:得出正确答案后,以自然语言的方式解释subsets的执行过程

Taking the 'and' of a list by folding in Scheme

独自空忆成欢 提交于 2020-02-25 04:02:19
问题 In the book Structure and Interpretation of Computer Programs by H. Abelson and G. J. Sussman with J. Sussman, the accumulation or fold-right is introduced in Section 2.2.3 as follows: (define (accumulate op initial sequence) (if (null? sequence) initial (op (car sequence) (accumulate op initial (cdr sequence))))) I tried to use this to take the and of a list of Boolean variables, by writing: (accumulate and true (list true true false)) However, this gave me the error and: bad syntax in

Trouble understanding / visualising SICP streams Hamming numbers program

て烟熏妆下的殇ゞ 提交于 2020-02-03 20:54:27
问题 I'm basically stuck at excercise 3.56 in SICP. The problem goes like this: 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 obvious way to do this is to simply test each integer in turn to see whether it has any factors other than 2, 3, and 5. But this is very inefficient, since, as the integers get larger, fewer and fewer of them fit the requirement. As

SICP学习笔记(1.1.6)

旧巷老猫 提交于 2020-01-29 04:16:40
SICP学习笔记(1.1.6) 周银辉 1, 语法糖衣 WIKIpedia上对于语法糖衣的解释是这样的: In computer science, syntactic sugar in a language is syntax designed to make things easier to read or to express, while alternative ways of expressing them exist. It makes the language "sweeter" for humans to use: things can be expressed more clearly, or more concisely, or in an alternative style that some may prefer. 最早接触到“糖衣”一词是在MaoZedong(写汉字居然不能发布,说有违禁内容,难道园子也安装上LvBa了?)同志的某篇讲话上,所以听到这词总觉得有些贬义夹杂在其中并暗示自己要小心提防。而在计算机科学上这似乎要理解成一个中性词甚至褒义词了,因为我们的确每天都在“享用”着这些“糖衣”为我们带来的甜头,比如C#中的“属性”,甚至C#3.0中的lambda表达式。注意,这里将C#的某些高级语法和“语法糖衣”一词联系了起来,请不要试图反驳什么,我没有贬义