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

The implement of "make-serializer" in SICP Section 3.4

In the book page 258, the authors implement make-serializer like this: (define (make-serializer) (let ((mutex (make-mutex))) (lambda (p) (define (serialized-p . args) (mutex 'acquire) (let ((val (apply p args))) …
0
votes
1 answer

Trying to implement a method to square a tree gives error 4 parts after keyword

I am trying to implement a method that has the ability to square a list that can consists of sub lists (a tree) using map. This means that (square-tree-map (list 1 3 (list 3 4))) should return (1 9 (9 16)). I came up with this code: (define…
user2609980
  • 10,264
  • 15
  • 74
  • 143
0
votes
4 answers

How to make this function elegant

In response to the following exercise from the SICP, Exercise 1.3. Define a procedure that takes three numbers as arguments and returns the sum of the squares of the two larger numbers. I wrote the following (correct) function: (define…
Elliot Gorokhovsky
  • 3,610
  • 2
  • 31
  • 56
0
votes
1 answer

Understanding exercise 2.29 SICP - Binary modules

Just one minor thing, I don´t understand why procedure right-branch is like this: (define (right-branch mobile) (car (cdr mobile))) instead of: (define (right-branch mobile) (cdr mobile)) As far as I know, car procedure return the first item…
Marcos
  • 4,643
  • 7
  • 33
  • 60
0
votes
2 answers

what is difference between (define (add x y) (+ x y)) and (define add (lambda (x y) (+ x y)))?

I am now writing a scheme's interpreter by using c++. I got a question about define and lambda. (define (add x y) (+ x y)) is expanded as (define add (lambda (x y) (+ x y))) by lispy.py what's the difference between this two expression? why need…
harborn
  • 15
  • 2
0
votes
3 answers

DrRacket doesn't run Ackermann function from SICP excercise 1.10

I recently started reading SICP and doing the excercies in the book. I installed both mit-scheme on command line and after tinkering with it a bit, I stumbled upon DrRacket and installed the SICP components from…
akaralar
  • 1,103
  • 1
  • 10
  • 29
0
votes
2 answers

Wrapper procedure for sort function failing because of argument

I'm working through SICP, and for one of the exercises I need to create a list of 2 of the 3 larger Numbers in the list. I'm trying to use sort function, but when I use it inside of a function, I'm getting an error: The object z, passed as the first…
Steven Spasbo
  • 647
  • 7
  • 18
0
votes
1 answer

When would a cons return a cascaded list?

I was doing exercise 2.18 of SICP(Structure and Interpretation of Computer Programs, 2nd edition) to make a program to reverse a list. And here is my code: (define (rev l) (if (null? (cdr l)) l (cons (rev (cdr l)) (car l)))) When I…
Mr.Zhou
  • 143
  • 1
  • 8
0
votes
1 answer

Scheme: Accelerated Stream

From this example code I found online, which functions are the unaccelerated stream, the singly-accelrated stream, and the super-accelerated stream? Thank you in advance. Cite: lawfulsamurai.blogspot.com/2009/01/sicp-section-35-streams.html (define…
King11
  • 1,239
  • 3
  • 9
  • 17
0
votes
1 answer

SICP exercise 1.10: Scheme evaluation of Ackermann's function

I'm working through Structure and Interpretation of Computer Programs and have a question concerning exercise 1.10, which, using Ackermann's function defined as (define (A x y) (cond ((= y 0) 0) ((= x 0) (* 2 y)) ((= y 1) 2) (else (A…
Brox
  • 117
  • 6
0
votes
1 answer

Scheme procedure problem

I defined the Scheme procedure to return another procedure with 2 parameters : (define (smooth f) (λ(x dx)(/ (+ (f (- x dx)) (f x) (f (+ x dx))) 3.0))) if i run this procedure with sin procedure with 2…
user305805
0
votes
3 answers

Let binding sequence as input to map, exception thrown

Coming from Functional Java and a little Scala, I am now learning Clojure step by step. At the moment, given that I have free time, I am reading and doing exercises from "Structure and Interpretation of Computer Programs". I am stuck at the…
Andrea Richiardi
  • 703
  • 6
  • 21
0
votes
2 answers

what is wrong this scheme code?

I'm studying sicp. this question is ex 1.3. I can't understand why this code is problem. please help me.. TT here's the code. (define (test a b c) (cond ((and (< a b) (< a c)) (+ (* b b) (* c c)) (and (< b a) (< b c)) (+ (* a…
0
votes
3 answers

SICP Exercise 2.33 issue

having a bit of a problem with this exercise. specifically, 'seeing' how the lambda expression works the exercise itself says this.. (define (map p sequence) (accumulate (lambda (x y) ) nil sequence)) has to turn into this... (define (map p…
user3435279
  • 85
  • 1
  • 8
0
votes
2 answers

dynamic value in scheme

I have been confused about the following program for a long time. in fact, it's a exercise of SICP 3.2 ;exercises 3.2 (define (make-monitored f) (define (monitor count) (define how-many-calls count) (define reset-count (set!…
user3754786
  • 57
  • 1
  • 6