Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
47 views

Getting wrong answer for cube-root procedure in Scheme [closed]

I wrote this code to compute the cube root of a number in Scheme: (define (square x) (* x x)) (define (abs x) (if (< x 0) (- x) x)) (define (cube x) (* x x x)) (define (cube-root-itr guess x) (...
Mohammad Abdullah Khan's user avatar
1 vote
1 answer
57 views

How to make `set!` change the variable in `let` (Scheme)?

Recently when I self-learnt MIT 6.5151 course, I have read SICP 1 to 2.1 as ps0 requires (also read 2.2.1 as CS 61A notes requires) and then Software Design for Flexibility (SDF) Prologue, chapter 1 ...
An5Drama's user avatar
  • 425
0 votes
1 answer
77 views

Why does Scheme use the procedural representation of pairs?

I am reading SICP. It says in 2.1.3: That is, the operations satisfy the condition that, for any objects x and y, if z is (cons x y) then (car z) is x and (cdr z) is y. ... Here are the definitions: ...
An5Drama's user avatar
  • 425
3 votes
1 answer
56 views

When can we safely use the Randomized algorithm considering probability?

Recently when reading SICP, one footnote says: Numbers that fool the Fermat test are called Carmichael numbers, and little is known about them other than that they are extremely rare. There are 255 ...
An5Drama's user avatar
  • 425
1 vote
1 answer
116 views

`1.0+1e-100=1.` in MIT-scheme

I am reading SICP and read this recitation about chapter 1. I use MIT/GNU Scheme as MIT course 6.5151 (6.905) does with version 12.1. I am stuck at Problem 3. Write a procedure that computes e. I ...
An5Drama's user avatar
  • 425
0 votes
0 answers
65 views

Is there some error-case in this answer? for SICP 1.7

I'm a beginner with SICP. For SICP 1.7, I assume this solution has some problem when '(improve guess x)' keeps returning different values compared to 'guess'. But I can't find an error case for this ...
DongHyun Chae's user avatar
0 votes
2 answers
85 views

Why in SICP one can see seemingly useless evaluation of local variable expressions? Different Scheme implementations behave differently

The deposit and withdraw procedures in the make-account code from SICP both have seemingly useless balance variable expression to evaluate, What is the practical purpose for doing that? (To me it ...
musthero's user avatar
  • 1,288
1 vote
1 answer
138 views

SiCP Exercise 1.45

Update: I changed the argument 1 in nth-root to 1.0, and then it works. Why are they different? Here's my original question. I have (define tolerance 0.00001) (define (fixed-point f first-guess) (...
run an's user avatar
  • 23
1 vote
4 answers
102 views

How to implement "if" in normal order in Scheme?

I was learning SICP and I read about "the applicative order" and "the normal order". Then I played around the Exercise 1-6 and looked into the following code: #lang racket (define (...
Mitchell Xu's user avatar
0 votes
3 answers
71 views

Why is the environment diagram in the following Python code inconsistent with its execution order?

When I was studying the SICP course, the execution order of the following code in the environment diagram is inconsistent with what I expected. def add_one(x): y = x+1 return y def square(x): ...
Quanjiang Liu's user avatar
2 votes
1 answer
165 views

How Can Lisp be defined in terms of y combinator?

I'm watching a lecture SICP 7A and struggling to understand "Define Lisp as Y combinator (time 1:16:15 )" I think I understood that expt ( calculating exponential of a number like x^n ) can ...
codeDog's user avatar
  • 53
1 vote
0 answers
51 views

Eval and Apply in SICP [duplicate]

What is so special about the SICP eval-apply loop? What is so enlightening about it? I understand the process of evaluation, but do not understand what is so universal in it. Programmers also say that ...
Gor's user avatar
  • 13
1 vote
1 answer
57 views

Is an iterative process that returns a list with size that increases by iteration any different from an one that returns a scalar?

This actually comes from me initially misreading the text of Exercise 1.12. The request is indeed to Write a procedure that computes elements of Pascal's triangle by means of a recursive process. I ...
Enlico's user avatar
  • 27.2k
1 vote
2 answers
169 views

Why normal-order and applicative-order evaluation are not giving the same value?

I am reading this book Structure and Interpretation of Computer Programs, 2nd edition and on page 21 under the subsection "Applicative order versus normal order" it is written that - It can ...
Charlie_23's user avatar
0 votes
1 answer
81 views

SICP Environment Diagram with Mermaid.JS

I'm trying to draw an environment diagram, as defined in SICP (see here), programmatically, such that a diagram will be associated with an evaluation of an expression. I'm testing Mermaid.js for that ...
Gino's user avatar
  • 759
1 vote
0 answers
31 views

SICP exercise 5.20

The exercise is from §5.3.1, and the text is copied below: Draw the box-and-pointer representation and the memory-vector representation (as in figure 5.14) of the list structure produced by (define x ...
Enlico's user avatar
  • 27.2k
1 vote
1 answer
39 views

What's the relevance of make-register accepting an argument (the name of the register) at all?

In §5.2.1, the following function is presented for creating a register (define (make-register name) (let ((contents '*unassigned*)) (define (dispatch message) (cond ((eq? message 'get) ...
Enlico's user avatar
  • 27.2k
1 vote
0 answers
36 views

Is this program recursive or iterative?

I started reading SICP and have a doubt in exercise 1.16: Exercise 1.16: Design a procedure that evolves an iterative exponentiation process that uses successive squaring and uses a logarithmic number ...
Hibiki's user avatar
  • 11
0 votes
0 answers
32 views

Chezscheme says "Exception: attempt to apply non-procedure #<void>" when I tried to print a pascal triangle [duplicate]

I'm new to scheme and I'm learning sicp. I'm working on exercise 1.12 and tried to print a pascal triangle with the code below. Cause I don't know much about scheme IO, I only used display procedure. (...
Van Young's user avatar
1 vote
2 answers
256 views

How is delay implemented?

I have a firm understanding of how lazy evaluation and streams work. However I'm having some trouble simply following the book at this point. I don't really undrestand what it is trying to tell me ...
Enlico's user avatar
  • 27.2k
1 vote
1 answer
52 views

About serializers as a mechanism for dealing with concurrency

tl;dr Is changing the former snippet below for the latter safe? Complete question In section §3.4.2 from SICP, the following function for creating an account balance able to cope with concurrent ...
Enlico's user avatar
  • 27.2k
0 votes
2 answers
48 views

Why an expression using a global variable multiple times reads that variable multiple times instead of just once?

At page 304 from SICP, the following snippet is shown (define x 10) (parallel-execute (lambda () (set! x (* x x))) (lambda () (set! x (+ x 1)))) about which it is said that x will ...
Enlico's user avatar
  • 27.2k
1 vote
2 answers
138 views

Evaluation of a self-referencing stream

I came across the following example in Lecture 6B of the SICP lecture series, and need some help understanding how it is evaluated. The example uses stream processing to create an infinite stream of ...
user51462's user avatar
  • 1,830
1 vote
0 answers
71 views

Highlight active parenthesis pair in vs code

How can I make vs code highlight inside a pair of parenthesis when put cursor at one of the parenthesis (this is drracket editor)
WestMountain's user avatar
1 vote
0 answers
136 views

How is the checker function implemented and updated here? (from CS61a UCB)

The question description is as follows: Implement div_by_primes_under, which takes in an integer n and returns an n-divisibility checker. An n-divisibility-checker is a function that takes in an ...
xucheng Zhu's user avatar
1 vote
0 answers
36 views

SICP- the expression of tree data structure in LISP [duplicate]

when I read SICP Section 2.2.2, we declare a sequence as (define x (cons (list 1 2) (list 3 4))) Then, when press x from my own DrRacket IDE and also the textbook, the result expression for this ...
Mark Dong's user avatar
1 vote
1 answer
109 views

SICP Integral Procedure

In SICP section 3.5 the following procedure is given (define (integral integrand initial-value dt) (define int (cons-stream initial-value (add-streams (scale-stream integrand dt) ...
Cruz Caine's user avatar
1 vote
0 answers
77 views

SICP stream integrator

In SICP chapter 3.5 the code for a integrator is given (define (solve f y0 dt) (define y (integral dy y0 dt)) (define dy (stream-map f y)) y) a signal-processing system for solving the ...
Cruz Caine's user avatar
1 vote
1 answer
133 views

SICP Exercise 1.8 - Why doesn't my function terminate?

I'm trying to implement Newton's method for cube roots, but my function seems to hang. My code is almost identical to the code the book shows for the square root, with the improve function modified as ...
Avrohom Yisroel's user avatar
1 vote
1 answer
674 views

SICP: Evaluate Racket into REPL with Emacs and Geiser

Working through SICP using Emacs, Geiser, and MIT Scheme, I decided to switch over to Racket in order to properly do the exercises in section 2.2.4 involving the Picture Language. Configuration I got ...
Patrick Bucher's user avatar
2 votes
2 answers
61 views

Error: #f is not a function [count-frac, (anon), (anon), (anon), (anon), =]

I'm trying to solve question 1.38 on SICP, and I encountered the bug as described in the title. Below is the description of the problem: In 1737, the Swiss mathematician Leonhard Euler published a ...
George Wu's user avatar
0 votes
1 answer
135 views

Logical AND as syntactic sugar for expression1 ? expression2 : false [duplicate]

I'm reading "Structure and Interpretation of Computer Programs: JavaScript Edition" (2022) by Abelson, Sussman et al. On page 64, the book talks about the "logical composition ...
Julia's user avatar
  • 21
0 votes
1 answer
41 views

Error: 1 is not a function [factorial, (anon), product, (anon), (anon), (anon), (anon)]

I'm working through SICP on my own. The function product is intended to return the product of the values of a function at points over a given range, and I'm trying to use it to define a function that ...
George Wu's user avatar
1 vote
3 answers
127 views

Why are <e> inside if and cond designed to be handled differently in Scheme?

(if <predicate> <consequent> <alternative>) (cond (<p1> <e1>) (<p2> <e2>) .......... (<pn> <en>)) A minor difference between if and cond ...
BBquestions's user avatar
0 votes
2 answers
63 views

Getting an wrong answer in scheme program

I am trying to find the cube root of a number using Newton's method. I wrote scheme procedures as follows: (define (cbrt x) (cbrt-iter 1.0 x)) (define (cbrt-iter guess x) (if (good-enough? ...
AK-CHP's user avatar
  • 101
1 vote
1 answer
87 views

SICP Exercise 1.19 PQ transformation

T(p,q) transforms the pair (a,b) according to a <-- bq + aq + ap and b <-- bp + aq. Can someone explain how this transformation works?
Cruz Caine's user avatar
0 votes
1 answer
111 views

Can we improve upon this primes sieve code from SICP

A recent Q&A entry showcased the following primes generating code from SICP, using lazy streams: (define (sieve stream) (cons-stream (stream-car stream) (sieve (stream-filter (...
Will Ness's user avatar
  • 70.8k
1 vote
2 answers
218 views

Need help to understand some of the SICP streams examples

I'm trying to understand how this function works. (define (sieve stream) (cons-stream (stream-car stream) (sieve (stream-filter (lambda (x) (not (divisible? x (stream-...
Alihan Aydin's user avatar
1 vote
1 answer
91 views

SICP Streams (Scheme) - CDR into the implicit stream of ones

(define ones (cons-stream 1 ones)) (stream-cdr ones) returns an infinite sequence of evaluated 1s - i.e. I get ;Value: #0={1 1 1 1 1 1 1 and so on... - not the symbolic {1 1 ...} I would expect ... ...
FooBant's user avatar
  • 404
1 vote
0 answers
78 views

Environments vs Frames in The Environment Model of Evaluation (SICP)

I found this section (3.2) of SICP pretty vague on the exact difference between an environment and a frame. Sometimes it seemed to use them interchangeably, and sometimes it labelled them as distinct ...
jim's user avatar
  • 1,023
0 votes
2 answers
86 views

Exercise 1.3 SICP why doesn't it work with 'when'?

#!/usr/bin/env racket #lang racket/base ;Define a procedure that takes three numbers as arguments and returns the sum of the ;squares of the two larger numbers. (define (procsq a b c) (when (and (&...
John Smith's user avatar
0 votes
2 answers
65 views

SICP exercise 1.15 Is operands evaluated prior to operators?

You can see the question here The code used is (define (cube x) (* x x x)) (define (p x) (- (* 3 x) (* 4 (cube x)))) (define (sine angle) (if (not (> (abs angle) 0.1)) angle (p (sine (/ ...
Pharrio's user avatar
0 votes
1 answer
233 views

Apply function to arguments or Apply arguments to function

Recently I am reading book SICP javascript. ( https://sourceacademy.org/sicpjs/1.1.4 ) And in this book ( chapter 1.1.4 ) I have a question about how function works. function-expression(argument-...
BeGood's user avatar
  • 11
2 votes
1 answer
214 views

Data-Directed Programming SICP

I have been trying to comprehend data-directed programming in SICP but couldn't so far. I have some questions about it. This is the original code from SICP: (define (make-table) (let ((local-table (...
PyotrVanNostrand's user avatar
1 vote
1 answer
121 views

Representing a queue as a procedure with local state

Section §2.1.3 at page 90 explains, with a very clear example, that first class functions in a language make functions themselves and data be the same thing looked at from different perspectives, or, ...
Enlico's user avatar
  • 27.2k
0 votes
0 answers
126 views

Closure techniques to hide function details

I have a recursive function that I would like to hide as an implementation detail. Here is are the two functions that I have to start: function f(n) { return fIter(2,1,0,n); } function fIter(a,...
David542's user avatar
  • 109k
0 votes
2 answers
48 views

Improve debugging output of a recursive function

I have the following recursive function to count the number of ways change can be returned given various coin denominations: function makeChange(amount, coins) { // Note: using Floats here ...
David542's user avatar
  • 109k
0 votes
1 answer
395 views

Regex to extract S expression?

I'm wondering if it's possible to do a pass on parsing of a define expression in lisp with a single regular expression, for example with the following input: #lang sicp (define (square x) (* x x)) (...
samuelbrody1249's user avatar
0 votes
3 answers
119 views

How to step through this evaluation?

I would like to see how the value of a square root is iteratively improved. For example on the following: #lang sicp (define (square x) (* x x)) (define (average x y) (/ (+ x y) 2)) (define (improve ...
David542's user avatar
  • 109k
0 votes
2 answers
601 views

How to run DrRacket program from command line?

I have the following program which I normally run from within DrRacket: ; 1.scm #lang sicp (display "hello\n") (+ 1 1) Is there a way to run the file directly as an executable, something ...
David542's user avatar
  • 109k

1
2 3 4 5
14