Questions tagged [sicp]

SICP is the book Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman with Julie Sussman and published by the MIT Press.

Quoting the wikipedia page:

Structure and Interpretation of Computer Programs (SICP) is a textbook published in 1984 about general computer programming concepts from MIT Press written by Massachusetts Institute of Technology (MIT) professors Harold Abelson and Gerald Jay Sussman, with Julie Sussman. It was formerly used as the textbook of MIT introductory programming class and at other schools.

Using a dialect of the Lisp programming language known as Scheme, the book explains core computer science concepts, including abstraction, recursion, interpreters and metalinguistic abstraction, and teaches modular programming.

The book is available online, with accompanying video lectures.

660 questions
9
votes
1 answer

Clojure- why doesn't this piece of code work in clojure, is there some lazy evaluation gotcha I am missing?

Am new to clojure and learning it by working through SICP. I cannot get this piece of code from SCIP 1.3.1 to work. What am I missing ? (defn sum [term a next b] (if (> a b) 0 (+ (term a) (sum term (next a) next b)))) (defn…
lordOfChaos
  • 113
  • 1
  • 5
9
votes
2 answers

Do I misunderstand the meaning of exercise 2.65 of SICP?

Here is the exercise 2.65 of SICP: Use the results of exercises 2.63 and 2.64 to give Θ(n) implementations of union-set and intersection-set for sets implemented as (balanced) binary trees. In the chapter "Sets as ordered lists" and exercise 2.62,…
yuliu
  • 913
  • 1
  • 6
  • 8
8
votes
5 answers

Fibonacci Tree-Recursion in Structure and Interpretation of Computer Programs

In the classic text by Abelson/Sussman, Structure and Interpretation of Computer Programs, in Section 1.2.2 on tree recursion and the Fibonacci sequence, they show this image: The tree-recursive process generated in computing for the 5th Fibonacci…
sicpfan
  • 81
  • 3
8
votes
3 answers

Question about SICP chpt 4.1 : How does (analyze expr) help speed up eval?

I'm reading the following section of SICP http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1.7 According to the text, the following transformation of eval will improve offers a performance improvement, since an expression that…
wk1989
  • 611
  • 1
  • 8
  • 19
8
votes
2 answers

Inconsistent box-and-pointer diagrams in SICP

Structure and Interpretation of Computer Programs (SICP)'s box-and-pointer diagrams in Figures 3.16 and 3.17 don't appear equivalent (purely with respect to value, not memory) even though it says they are. ("When thought of as a list, z1 and z2 both…
Aaron
  • 135
  • 7
8
votes
2 answers

Is there any difference between closure in Scheme and usual closure in other languages?

I'm studying SICP right now. And I found the definition of closure in SICP is (maybe) different from closure definition in other languages. Here's what SICP says: The ability to create pairs whose elements are pairs is the essence of list…
yuanqili
  • 392
  • 3
  • 12
8
votes
2 answers

How to use scheme macros to show evaluation tree

I modified the code for the count-change function in SICP so that it would display a pair whenever the function recurses. The pair is of the form "(cc a k)" -> "(cc a (- k 1))" or "(cc a k)" -> "(cc (- a (d k)) k)", my goal is to build up a DOT file…
tlehman
  • 5,125
  • 2
  • 33
  • 51
7
votes
2 answers

How to deeply understand the signal-flow diagram described in SICP?

SICP Chapter 3.5.3 http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#%_sec_3.5.3 In section Streams as signals, SICP gives an audio-visual explanation of Implicit style of definition -- by feedback loop. But I want to know how to exactly…
Yai0Phah
  • 433
  • 4
  • 14
7
votes
3 answers

Why apply is so important for lisp evaluator?

I have read chapter 4 of SICP, and just found that the first section lists the most important functions for implementing a evaluator, eval and apply, I understand that eval is very important, but why apply is so important? For some language, there…
Thomson
  • 20,586
  • 28
  • 90
  • 134
7
votes
1 answer

What is the real answer to SICP 3.57

SICP 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 would be exponentially greater if we had implemented…
nate
  • 71
  • 4
7
votes
3 answers

Examining the internals of the functions in Haskell

I am a Haskell newbie, though had a previous Lisp/Scheme experience. Right now I am looking at the examples from SICP and trying to implement them in Haskell to get more hands-on experience. In the lecture 3b authors present a function for computing…
Sergey Mikhanov
  • 8,880
  • 9
  • 44
  • 54
7
votes
1 answer

Does the DrRacket interpreter use normal-order evaluation based on SICP Exercise 1.5?

One must decide, based on the value of: (test 0 (p)) where test is defined as : (define (test x y) (if (= x 0) 0 y)) and p is defined as : (define (p) (p)) When I evaluate (test 0 (p)) the interpreter goes into an infinite loop,…
Geoffrey
  • 5,407
  • 10
  • 43
  • 78
7
votes
6 answers

In SICP exercise 2.26 using DrScheme, why does cons return a list, instead of a pair of lists?

In SICP exercise 2.26, this Scheme code is given: (define x (list 1 2 3)) (define y (list 4 5 6)) Then this cons call is given: (cons x y) I expected a pair of lists would result, ((1 2 3) (4 5 6)) but the interpreter gives, ((1 2 3) 4 5 6) ...a…
limist
  • 1,288
  • 2
  • 16
  • 29
7
votes
4 answers

using lambda instead of let in scheme

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…
CamelCamelCamel
  • 5,200
  • 8
  • 61
  • 93
7
votes
2 answers

How is the sicp cons-stream implemented?

I'm working through the streams section of the scip and am stuck on how to define a stream. The following is my code: (define (memo-func function) (let ((already-run? false) (result false)) (lambda () (if (not already-run?) …
zcaudate
  • 13,998
  • 7
  • 64
  • 124