sicp

How do I get a scheme interpreter working inside Emacs?

浪子不回头ぞ 提交于 2019-11-29 21:05:29
I'm going through SICP and I'd like to have an interpreter analogous to the interactive Python interpreter to play around in while I'm watching the lectures and reading the book. Furthermore, I'd like this interpreter to run inside Emacs so I can jump back and forth between files of scheme code and the interactive interpreter and so forth. However, I'm fairly new to Emacs and have not as of yet been able to get this to work or find one clear set of instructions to use in getting it to work. It seems like I should be able to set it up so that M-x run-scheme will open up an interactive

mcons in dr racket

那年仲夏 提交于 2019-11-29 18:15:07
问题 I'm having trouble reading output from dr racket. By default it displays lists using mcons. For example, sicp exercise 2.32 produces: > (subsets (list 1 2 3)) (mcons (mcons '() (mcons (mcons 3 '()) (mcons (mcons 2 '()) (mcons (mcons 2 (mcons 3 '())) (mcons (mcons 1 '()) (mcons (mcons 1 (mcons 3 '())) (mcons (mcons 1 (mcons 2 '())) (mcons (mcons 1 (mcons 2 (mcons 3 '()))) '())))))))) '()) I'm having trouble reading this. Is there a way to make the output look like: (() (3) (2) (2 3) (1) (1 3)

Understanding the environment model of evaluation

冷暖自知 提交于 2019-11-29 16:11:25
Exercise 3.20 in SICP: Draw environment diagrams to illustrate the evaluation of the sequence of expressions (define x (cons 1 2)) (define z (cons x x)) (set-car! (cdr z) 17) (car x) 17 using the procedural implementation of pairs given above. My eyes are destroyed so I cannot draw. I will instead try to imagine as best as I can how the environment model evolves. First, here is the procedural pairs implementation. (define (cons x y) (define (set-x! v) (set! x v)) (define (set-y! v) (set! y v)) (define (dispatch m) (cond ((eq? m 'car) x) ((eq? m 'cdr) y) ((eq? m 'set-car!) set-x!) ((eq? m 'set

SICP example: Counting change, cannot understand

老子叫甜甜 提交于 2019-11-28 23:36:15
I am a beginner following SICP course on MIT OpenCourseWare using both the video lectures and the book available online. Yesterday I came across an example, which ask if we can write a procedure to compute the number of ways to change any given amount of money. This problem has a simple solution as a recursive procedure: (define (count-change amount) (cc amount 5)) (define (cc amount kinds-of-coins) (cond ((= amount 0) 1) ((or (< amount 0) (= kinds-of-coins 0)) 0) (else (+ (cc amount (- kinds-of-coins 1)) (cc (- amount (first-denomination kinds-of-coins)) kinds-of-coins))))) (define (first

Dr Racket problems with SICP

耗尽温柔 提交于 2019-11-28 16:51:48
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. Eli Barzilay Even if possible, such redefinitions are not something that you should do without really understanding how

Tail-recursive Pascal triangle in Scheme

丶灬走出姿态 提交于 2019-11-28 12:25:31
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 recursive However, for a "two dimensional" situation, like calculating Pascal's triangle (Ex 1.12 in SICP), we

How to express let* as a lambda expression (not the regular let)

末鹿安然 提交于 2019-11-28 08:06:59
问题 I have a scheme related question, how can we implement let* as a lambda expression. To be more precise, I am not wondering about the "regular" let, but the let with * which lets us use one let expression within another. 回答1: The let* form is a series of nested lambda s. For example, this: (let* ((a 10) (b (+ 10 a))) (+ a b)) Is equivalent to this: ((lambda (a) ((lambda (b) (+ a b)) (+ 10 a))) 10) 回答2: Since you are not wondering about the 'regular' let , if a let* can be converted into let

What is the best Scheme implementation for working through SICP?

邮差的信 提交于 2019-11-27 17:14:34
I have been using PLT Scheme , but it has some issues. Does anyone know of a better implementation for working through SICP? 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. 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 DrRacket you can now see the images directly in the REPL (the read-eval-print-loop). SICP Support for DrRacket ,

SICP example: Counting change, cannot understand

只谈情不闲聊 提交于 2019-11-27 15:05:08
问题 I am a beginner following SICP course on MIT OpenCourseWare using both the video lectures and the book available online. Yesterday I came across an example, which ask if we can write a procedure to compute the number of ways to change any given amount of money. This problem has a simple solution as a recursive procedure: (define (count-change amount) (cc amount 5)) (define (cc amount kinds-of-coins) (cond ((= amount 0) 1) ((or (< amount 0) (= kinds-of-coins 0)) 0) (else (+ (cc amount (- kinds

SICP recursive process vs iterative process: using a recursive procedure to generate an iterative process

跟風遠走 提交于 2019-11-27 14:49:11
in SICP Section 1.2.1 The author giving such a code example below to show how to using iterative process to solve the factorial problem: (define (factorial n) (fact-iter 1 1 n)) (define (fact-iter product counter max-count) (if (> counter max-count) product (fact-iter (* counter product) (+ counter 1) max-count))) and say "It may seem disturbing that we refer to a recursive procedure such as fact-iter as generating an iterative process.However, the process really is iterative: Its state is captured completely by its three state variables, and an interpreter need keep track of only three