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

Memoization during delayed evaluation

The book Structure and Interpretation of Computer Programs introduces a memoizing procedure as follows: (define (memo-proc proc) (let ((already-run? false) (result false)) (lambda () (if (not already-run?) (begin (set! result…
loudandclear
  • 2,306
  • 1
  • 17
  • 21
6
votes
3 answers

Streams in Scheme - define integers through stream map in scheme

How can I define integers through stream-map in Scheme: (define integers (stream-cons 1 (stream-map *something* *something*))
nanachan
  • 1,051
  • 1
  • 15
  • 26
6
votes
2 answers

SICP exercise 1.5 and 1.6

In addition to question What's the explanation for Exercise 1.6 in SICP?. So Dr. Racket (R5RS) evaluates sqrt-iter function with "if" in finite time, clearly showing normal order evaluation. But if I use example from exercise 1.5 (define (p)…
Vasaka
  • 579
  • 6
  • 17
5
votes
3 answers

Why separating syntax analysis from execution?

In SICP Chapter 4, the metacircular evaluator is modified by separating the syntax analysis from the execution, making the eval procedure look like: (define (eval exp env) ((analyze exp) env)) and the book says that this will save work since…
pjhades
  • 1,948
  • 2
  • 19
  • 34
5
votes
2 answers

The implement of mutex in SICP Section 3.4

When the authors implement the mutex part of serializers, they use a list called cell. But the list only contains one element, so why not just use a variable?
Bin Wang
  • 2,697
  • 2
  • 24
  • 34
5
votes
1 answer

Including an r5rs file into another file in racket

One of my courses is using DrRacket for some sections of SICP. We're working on the metacircular evaluator and I have an R5RS code file (set-car! and set-cdr!) which I need to use with my work. Because the R5RS file is roughly 500 lines, I'd prefer…
Kizaru
  • 2,443
  • 3
  • 24
  • 39
5
votes
2 answers

A better explanation of using stream to generate numbers with alternating signs

The code here can generate numbers like this [1 -2 3 -4 5 -6 7 -8 9 -10 ...] (define (integers-starting-from n) (cons-stream n (stream-map - (integers-starting-from (+ n 1))))) I don't quite understand the way it generates alternating signs. Can…
yang-qu
  • 2,144
  • 4
  • 20
  • 26
5
votes
3 answers

Space complexity of streams in Scheme

I am reading Structure and Interpretation of Computer Programs (SICP) and would like to make sure that my thinking is correct. Consider the following simple stream using the recursive definition: (define (integers-starting-from n) (cons-stream n…
5
votes
1 answer

In this concrete case, how is "trace" supposed to work in Racket?

I am using the famous book SICP. On the exercise 1.18 a strange thing happens. I wrote this code: (define (double n) (* 2 n)) (define (halve n) (/ n 2)) (define (fast-mult a b) (fast-mult-iter a b 0)) (define (fast-mult-iter a b counter) …
user4206400
5
votes
3 answers

In SICP 3.2, The Environment Model of Evaluation, is an environment initially the same as its first frame?

In The Structure and Interpretation of Computer Programs part 3.2, an "environment" is defined as "a sequence of frames." But as far as I can see, the book doesn't further discuss the difference between an environment and a frame. Also, I suspect…
limist
  • 1,288
  • 2
  • 16
  • 29
5
votes
1 answer

Order of evaluation, SICP exercise

So, I'm working my way through SICP. First exercise of Chapter 4 is: Exercise 4.1. Notice that we cannot tell whether the metacircular evaluator evaluates operands from left to right or from right to left. Its evaluation order is inherited from…
Mathieu Borderé
  • 4,357
  • 2
  • 16
  • 24
5
votes
3 answers

Causes of stack overflow in recursive functions

In this video around the 28 minute mark, Brian Harvey was asked by a student if we should always use an iterative process over a recursive process when writing programs. He said no, because Your programs are not gonna run into space limitations.…
lightning_missile
  • 2,821
  • 5
  • 30
  • 58
5
votes
1 answer

Change output printing style from Racket REPL

I'm doing problems from SICP, using the #lang planet/neil directive in Racket. I'd prefer to write my code in Emacs, and I'm using Geiser-mode to run a Racket REPL through Emacs. The way racket prints results tends to use a lot of mcons which makes…
crowding
  • 1,498
  • 10
  • 11
5
votes
1 answer

don't understand scheme procedure in SICP

i'm working through SICP Chapter 1 "1.3 Formulating Abstractions with Higher-Order Procedures" the part i'm (currently) having trouble with is where the procedural template (shown below) is transformed into an actual procedure (shown below that) by…
user3435279
  • 85
  • 1
  • 8
5
votes
1 answer

SICP Infinite Streams (Chapter 3.5.2)

This is a question related to the SICP Book Chapter 3.5.2. I'm implementing a stream data structure in other programming languages. And I'm not sure if I understand the following snippet correctly. (define (integers-starting-from n) …
Yeo
  • 11,416
  • 6
  • 63
  • 90