sicp

Dr Racket problems with SICP

戏子无情 提交于 2019-11-27 10:00:13
问题 I'm working through SICP. Currently, in the first chapter, I'm having problems getting Racket to let me redefine "primitives". For instance, I was under the impression that I should be able to arbitrarily do (define + 5) and that would be fine, or redefine the sqrt procedure. Instead, I get this: define-values: cannot change constant variable: + I have the language currently set to R5RS, which I was under the impression would take care of the compatibility issues with SICP. 回答1: Even if

Tail-recursive Pascal triangle in Scheme

落爺英雄遲暮 提交于 2019-11-27 07:10:52
问题 I started to read SICP recently, and I'm very interested in converting a recursive procedure into a tail-recursive form. For "one dimensional" situations (linear ones), like the Fibonacci series or factorial computation, it is not hard to do the conversion. For example, as the book says, we can rewrite the Fibonacci computation as follows (define (fib n) (fib-iter 1 0 n)) (define (fib-iter a b count) (if (= count 0) b (fib-iter (+ a b) a (- count 1)))) And this form is obviously tail

What is the best Scheme implementation for working through SICP?

感情迁移 提交于 2019-11-26 22:32:57
问题 I have been using PLT Scheme, but it has some issues. Does anyone know of a better implementation for working through SICP? 回答1: Use MIT Scheme. It's recommended by the authors of SICP, and is used at MIT for the 6.001: Structure and Interpretation of Computer Programs course. 回答2: Use Racket (formerly PLT Scheme). The DrRacket IDE is an excellent starting point for all things Scheme including SICP. To look up keywords in the documentation, place the cursor on the keyword and press F1 . In

Use of lambda for cons/car/cdr definition in SICP

别说谁变了你拦得住时间么 提交于 2019-11-26 18:54:10
I was just beginning to feel I had a vague understanding of the use of lambda in racket and scheme when I came across the following 'alternate' definitions for cons and car in SICP (define (cons x y) (lambda (m) (m x y))) (define (car z) (z (lambda (p q) p))) (define (cdr z) (z (lambda (p q) q))) For the life of me I just cannot parse them. Can anybody explain how to parse or expand these in a way that makes sense for total neophytes? Óscar López This is an interesting way to represent data: as functions. Notice that this definition of cons returns a lambda which closes over the parameters x

Use of lambda for cons/car/cdr definition in SICP

纵饮孤独 提交于 2019-11-26 06:40:25
问题 I was just beginning to feel I had a vague understanding of the use of lambda in racket and scheme when I came across the following \'alternate\' definitions for cons and car in SICP (define (cons x y) (lambda (m) (m x y))) (define (car z) (z (lambda (p q) p))) (define (cdr z) (z (lambda (p q) q))) For the life of me I just cannot parse them. Can anybody explain how to parse or expand these in a way that makes sense for total neophytes? 回答1: This is an interesting way to represent data: as

Which lang packet is proper for SICP in Dr.Racket?

荒凉一梦 提交于 2019-11-26 02:56:31
问题 I\'m trying with SICP and I got some code. So I started with: #lang scheme (word \'comp \'uter) Returned error: Function (word) undefined. Even if I tried to copy this into IDE(Run): (define word? (let ((number? number?) (symbol? symbol?) (string? string?)) (lambda (x) (or (symbol? x) (number? x) (string? x))))) Still the same. I think it may be certain problem with version of language or else. Above are from \"Simply Scheme\" and when I introduce code exactly in SICP: (define (sqrt x) (sqrt