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
3
votes
2 answers

Send code to scheme interpreter from info buffer

I want to study SICP in my Emacs. I've installed MIT Scheme, Emacs 24 and downloaded sicp info (using this guide http://www.pchristensen.com/blog/articles/setting-up-and-using-emacs-infomode/). Now I'm able to run scheme interpreter in dedicated…
3
votes
6 answers

How to improve this piece of code?

My solution to exercise 1.11 of SICP is: (define (f n) (if (< n 3) n (+ (f (- n 1)) (* 2 (f (- n 2))) (* 3 (f (- n 3)))) )) As expected, a evaluation such as (f 100) takes a long time. I was wondering if there was a way to improve this…
user59634
3
votes
3 answers

Loading libraries in Dr Scheme

I am working through SICP using Dr Scheme. How do I load external libraries in Dr Scheme? Say I want to use Math library then how do I ask Dr Scheme to load the particular library? I tried with the following: (require (lib "math.ss")) Got the…
abhirama
3
votes
3 answers

Does "map" necessarily produce an additional level of nesting?

Does using nested maps automatically create another level of nesting? Here is a basic example that I used: ; One level (map (lambda (x1) "Hi") '(1)) ; Two levels (map (lambda (x1) (map (lambda (x2) "Hi") '(1))) …
David542
  • 104,438
  • 178
  • 489
  • 842
3
votes
2 answers

The apply function in SICP/Scheme

I've asked a few questions here about Scheme/SICP, and quite frequently the answers involve using the apply procedure, which I haven't seen in SICP, and in the book's Index, it only lists it one time, and it turns out to be a footnote. Some examples…
David542
  • 104,438
  • 178
  • 489
  • 842
3
votes
3 answers

Ternary conditions to find expmod?

I am reading SICP in JS about a non-terminating example of ternary conditions: function is_even(n) { return n % 2 === 0; } function expmod(base, exp, m) { const half_exp = expmod(base, exp / 2, m); return exp === 0 ? 1 :…
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138
3
votes
1 answer

Without prior knowledge of Scheme's floor and rounding functions, how can SICP Exercise 1.45 (making an nth root function) be completed?

While completing SICP's Exercise 1.45, one soon notices that the number of times that the average-damp procedure needs to be applied to find the nth root of a number is very well approximated by the base 2 logarithm of n, rounded down. In other…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
3
votes
1 answer

How does SICP intend the (if) forms without their alternative (else) part to work?

Exercise 1.22 of SICP contains the following procedure: (define (start-prime-test n start-time) (if (prime? n) (report-prime (- (runtime) start-time)))) To my eyes, the if form has no alternative branch. I can only see if (test)…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
3
votes
2 answers

Mathematically, why does this SICP algorithm for the exponent of a number modulo another number work?

Section 1.2.6 of SICP gives the following procedure: (define (expmod base exp m) (cond ((= exp 0) 1) ((even? exp) (remainder (square (expmod base (/ exp 2) m)) m)) (else (remainder (* base…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
3
votes
1 answer

(SICP) What is the difference between functions and procedures?

I am currently working my way through Structure and Interpretation of Computer Programs doing both the book and lectures from Brian Harvey(who is hilarious at points), however I have yet to truly have my "aha! moment" with differentiating functions…
3
votes
1 answer

Problem with Generic Function in Rust with integers and floats. Working through Structure and Interpretation of Computer Programs in Rust

I have this so far. And I can not find a way to deal with the comparison with good_enough. I am working through Structure and Interpretation of Computer Programs and I would like to conform best I can to the practices in the book. Scheme is easy.…
3
votes
2 answers

Creating a generator for primes in the style of SICP

In a future course, I'll be having a discipline that uses Python with an emphasis of using sequences and generators and that kind of stuff inn Python. I've been following an exercise list to exercise these parts. I'm stuck on an exercise that asks…
tigre200
  • 184
  • 1
  • 10
3
votes
1 answer

Why do I get an "arity mismatch" error? Exercise 1.43 in SICP

I'm working on exercise 1.43 from The Structure and Interpretation of Computer Programs. Exercise 1.43. If f is a numerical function and n is a positive integer, then we can form the nth repeated application of f, which is defined to be the…
tanliang
  • 49
  • 3
3
votes
3 answers

With applicative order, what order are the arguments evaluated? Left to right or right to left?

In SICP part 1.1.5 The Substitution Model for Procedure Application I am curious about the applicative order of evaluation. I understand that applicative order evaluates the arguments before applying the outer procedure. My question is what order…
joejoemac
  • 155
  • 10
3
votes
1 answer

scheme which support set-car! and set-cdr! in sicp

I am reading SICP 4.1.3 Evaluator Data Structures (define (make-frame variables values) (cons variables values)) (define (frame-variables frame) (car frame)) (define (frame-values frame) (cdr frame)) (define (add-binding-to-frame! var val frame) …
AbstProcDo
  • 19,953
  • 19
  • 81
  • 138