sicp

SICP, Continuation Passing Style and Clojure's trampoline

╄→гoц情女王★ 提交于 2020-01-01 19:19:09
问题 I am working with SICP and exercise 2.29-b gave me the opportunity to have fun with the Continuation Passing Style while traversing mobiles and branches. To make the story short, each mobile has left and right branch, which are composed by a length and either a numeric weight or another mobile. The question asks to find the total weight given a mobile. After the first mutually recursive solution, quite simple, I tried and successfully implemented a cps' one: (defn total-weight-cps [mobile]

using lambda instead of let in scheme

旧时模样 提交于 2020-01-01 09:28:11
问题 In SICP 1.2.1 there is a function that makes a rational number, as follow: (define (make-rat n d) (let ((g (gcd n d))) (cons (/ n g) (/ d g)))) I'm just curious how you can implement the same thing using lambda instead of let, without calling GCD twice. I couldn't figure it out myself. 回答1: Looking at SICP section 1.3.2, (let ((<var1> <exp1>) (<var2> <exp2>) ... (<varn> <expn>)) <body>) is equivalent to ((lambda (<var1> ...<varn>) <body>) <exp1> ... <expn>) So your procedure, (define (make

What interpreter to use while reading SICP? [closed]

一世执手 提交于 2019-12-31 04:45:20
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 5 years ago . I'm reading SICP book available at http://mitpress.mit.edu/sicp/ To run the sample code which interpreter should I use ? I've considered Dandelion Lisp plugin for Eclipse : http://sourceforge.net/projects/dandelion-ecl/ Also considered Scheme for windows http://www.gnu.org/software/mit-scheme/ Which one should I

seek for some explanation on SICP exercise 1.5

谁说胖子不能爱 提交于 2019-12-30 17:55:22
问题 The question can be found here. In the book, I found one description of normal order evaluation was: "An alternative evaluation model would not evaluate the operands until their values were needed. Instead it would first substitute operand expressions for parameters until it obtained an expression involving only primitive operators, and would then perform the evaluation." I also found another description in short: "fully expand and then reduce". In the exercise, I thought the definition of p

【SICP练习】152 练习4.8

余生长醉 提交于 2019-12-27 17:35:23
练习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 and whose parameters are the variables in the . Thus, one can repeatedly execute the by invoking the procedure named . For example, the iterative Fibonacci procedure (section 1.2.2) can be rewritten using named let as follows: (define (fib n) (let fib-iter ((a 1) (b 0) (count n)) (if (= count 0) b (fib-iter (+ a b) a (- count 1))))) Modify let->combination of exercise 4.6 to also support named let.

SICP 第一章 构造过程抽象 1

本秂侑毒 提交于 2019-12-27 00:03:10
Chapter 1 Building Abstractions with Procedures /*--> */ /*--> */ Chapter 1 Building Abstractions with Procedures Table of Contents 1. 构造过程抽象 1.1. 程序设计的基本元素 1.1.1. 表达式(expressions) 1.1.2. 命名和环境 1.1.3. 组合式的求值 1.1.4. 复合过程(compound procedures) 1.1.5. 过程应用的代换模型 1.1.6. 条件表达式和谓词 1.1.7. 练习 1.1.8. 实例:采用牛顿法求平方根 1.1.9. 过程作为黑箱抽象 1.1.10. 练习 1 构造过程抽象 心智活动就是: 组合. 将 simple ideas 变成 compound ideas 关系. 将idea放在一起, setting them by one another, 同时观察. 抽象. 隔离开实际中的相伴的其他idea, 从而抽取出 general idea. 我们研究 the idea of a computational process. 计算过程(computational process) 计算机中的 抽闲存在, 操作 data. 一套规则即 program

What's the explanation for Exercise 1.6 in SICP?

百般思念 提交于 2019-12-20 08:31:24
问题 I'm just beginning to work through SICP (on my own; this isn't for a class), and I've been struggling with Exercise 1.6 for a couple of days and I just can't seem to figure it out. This is the one where Alyssa re-defines if in terms of cond , like so: (define (new-if predicate then-clause else-clause) (cond (predicate then-clause) (else else-clause)) She tests it successfully on some simple cases, and then uses it to re-write the square root program (which worked just fine with if ): (define

How to order my accumulate variable in this case on Racket?

陌路散爱 提交于 2019-12-20 04:36:31
问题 I am coding with Racket for educational reasons. I was given a task in which I should create a function that, without filter, would receive a list as an input and return another list only with the even numbers of the first list. I came up with this recursive definition of an iterative process: (define (add-even lista) (define (iter lista accu) (cond ((null? lista) accu) ((even? (car lista)) (iter (cdr lista) (cons (car lista) accu))) (else (iter (cdr lista) accu)))) (iter lista empty)) It

Running SICP Pattern Matching Rule Based Substitution Code

蓝咒 提交于 2019-12-18 11:53:24
问题 I have found the code from this lesson online (http://groups.csail.mit.edu/mac/ftpdir/6.001-fall91/ps4/matcher-from-lecture.scm), and I am having a heck of a time trying to debug it. The code looks pretty comparable to what Sussman has written: ;;; Scheme code from the Pattern Matcher lecture ;; Pattern Matching and Simplification (define (match pattern expression dictionary) (cond ((eq? dictionary 'failed) 'failed) ((atom? pattern) (if (atom? expression) (if (eq? pattern expression)

Which language in DrScheme for SICP?

江枫思渺然 提交于 2019-12-18 11:51:52
问题 I have been using the Module for SICP in DrScheme 4.2 but which language has the best support for SICP in DrScheme? Has anyone here tried this? Thanks. 回答1: I don't think you need anything but R5RS which is available in DrScheme via Language > Choose Language... . You might want to allow redefinition of bindings. After you have selected R5RS, click on " Show Details " and uncheck " Disallow redefinition of initial bindings ". Some places in the text uses an error function, which is not