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
5
votes
1 answer

Reconciling lazy evaluation with complexity analysis

In the streams 2 video of SICP, Abelson gives an example of using an analog computer solving differential equations. He then programs this in Scheme, using lazy evaluation to get around a circular definition dependency. The problem with this…
Jeff Linahan
  • 3,775
  • 5
  • 37
  • 56
5
votes
2 answers

SICP 1.31: Approximating Pi

I'm working through SICP on my own, so I don't have an instructor to ask about this. This code is supposed to approximate pi but always returns zero instead. (define (approx-pi acc) (define (factors a) (define basic-num (if (= (mod a…
gregsabo
  • 430
  • 2
  • 9
5
votes
2 answers

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

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.
Arash Saidi
  • 2,228
  • 20
  • 36
4
votes
2 answers

Is the Church numeral encoding of natural numbers unnecessarily complicated?

The Structure and Interpretation of Computer Programs book I've been reading presents Church numerals by defining zero and an increment function zero: λf. λx. x increment: λf. λx. f ((n f) x) This seemed pretty complicated to me and it took me a…
Peter Olson
  • 139,199
  • 49
  • 202
  • 242
4
votes
2 answers

SICP exercise 3.8 - Why the procedure works? (I think it's about the environment)

The exercise 3.8 in the SICP is described as blow: When we defined the evaluation model in section 1.1.3, we said that the first step in evaluating an expression is to evaluate its subexpressions. But we never specified the order in which the …
Bin Wang
  • 2,697
  • 2
  • 24
  • 34
4
votes
0 answers

Assignment statement - considered harmful?

I came across this video of Uncle Bob speaking about the SICP book and the assignment statement and it made me think (and read the corresponding chapter from SICP). I'm wondering whether the arguments listed (local state, side effects, etc.),…
Igor Popov
  • 9,795
  • 7
  • 55
  • 68
4
votes
3 answers

How many of these points in the definition of a first-class element do Java's functions satisfy?

Structure and Interpretation of Computer Programs gives the following as the conditions that an element of a programming language must satisfy to be considered first-class: They may be named by variables. They may be passed as arguments to…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
4
votes
3 answers

Is it still inadvisable to define constructors and selectors as cons, car, and cdr?

Structure and Interpretation of Computer Programs has the following footnote: Another way to define the selectors and constructor is (define make-rat cons) (define numer car) (define denom cdr) The first definition associates the name make-rat with…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
4
votes
4 answers

python delayed execution

To implement streams as delayed lists in Lisp it's recommended to use Lisp macros. (defmacro cons-stream (a b) (cons ,a (delay ,b))) (defmacro delay (expr) `(memo-proc (lambda () ,expr))) What would by Python and Perl way to do the same…
Oleg Pavliv
  • 20,462
  • 7
  • 59
  • 75
4
votes
1 answer

Why does my iterative higher-order procedure give more precise results than my equivalent recursive procedure?

Exercise 1.30 of SICP invites us to rewrite the following code as an iterative (read: tail recursive) procedure: (define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) next b)))) To assist us, we are given…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
4
votes
2 answers

What is Order of Growth and How do you compute it?

Why I am asking this question I have recently started reading Sicp, and I have worked my way through to Section 1.2.3. I am unable to understand some of the details of Order of Growth. Please bear with me and my overly long question. Please also…
4
votes
1 answer

Unclear how the get procedure works inside apply-generic (SICP)

In the book The Structure and Interpretation of Computer Programs, Section 2.4.3, it says that: (get ) looks up , entry in the table and returns the item found there. and apply-generic is defined as (define (apply-generic op .…
Brady Dean
  • 3,378
  • 5
  • 24
  • 50
4
votes
1 answer

SICP exercise 3.67 - producing all pairs of integers without restrictions

From SICP: This is an infinite stream of ones: (define ones (cons-stream 1 ones)) This is an infinite stream of positive integers: ; add-streams takes two streams and produces a stream of their elementwise sum (define integers (cons-stream 1…
lightning_missile
  • 2,821
  • 5
  • 30
  • 58
4
votes
2 answers

SICP 1.45 - Why are these two higher order functions not equivalent?

I'm going through the exercises in [SICP][1] and am wondering if someone can explain the difference between these two seemingly equivalent functions that are giving different results! Is this because of rounding?? I'm thinking the order of functions…
ajivani
  • 414
  • 1
  • 6
  • 11
4
votes
3 answers

base case and time complexity in recursive algorithms

I would like some clarification regarding O(N) functions. I am using SICP. Consider the factorial function in the book that generates a recursive process in pseudocode: function factorial1(n) { if (n == 1) { return 1; } return…
lightning_missile
  • 2,821
  • 5
  • 30
  • 58