8,172
questions
2
votes
3
answers
72
views
How to evaluate conditionals not deterministic (random order) in Racket/Scheme?
How do I evaluate this code un-deterministically?
(cond (correct-1? do-thing-1)
(correct-2? do-thing-2)
(correct-3? do-thing-3))
For example, if correct-1? and correct-3? are true, then I ...
0
votes
1
answer
50
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)
(...
0
votes
1
answer
38
views
Unbound variable error in cube root function
The code is as follows:
(define (square x) (* x x))
(define (abs x) (if (< x 0) (- x) x))
(define (sqrt-iter guess x)
(if (good-enough? guess x)
guess
(sqrt-iter (improve guess x) x)))
...
0
votes
0
answers
15
views
Using top level bindings in modules in a program that uses C and Guile cooperation
I have a .c program which starts a Guile repl.
It then defines some wrappers using the
scm_c_define_gsubr
function.
Then it loads an init .scm file.
In this .scm file I load some modules.
These ...
0
votes
0
answers
43
views
Adding one careless dot in Scheme code works with one weird result without throwing syntax errors [duplicate]
Recently when I am coding my homework using Scheme language, I carelessly added one dot. Here is one minimal demo:
(define (test value)
(vector-map
(lambda (elem)
(cond
((number?...
0
votes
0
answers
43
views
Dates in chez-scheme according to the gregorian calendar (< 01.01.1970)
I need to work with dates that contain birth dates. The program must therefore be able to process dates before 1970. Otherwise I would not be able to calculate the age of a person who was born in 1955,...
1
vote
1
answer
49
views
What is the relation of parent env and the child env in MIT-Scheme?
When we call (environment-lookup system-global-environment name) where system-global-environment is the parent of top-level-environment, will it also look up in its child env?
From the doc, it seems ...
0
votes
0
answers
57
views
How to write `compose` similar to that in SDF with python?
Recently when I self-learnt MIT 6.5151 course, I first read CS 61AS Unit 0 as the preparation. Then I have read SICP 1 to 2.1 (with related lecture notes) as ps0 requires (also read 2.2.1 as CS 61A ...
1
vote
0
answers
73
views
Weird definition of `close-enuf?` in Software Design for Flexibility
MIT 6.5151 course code base based on book Software Design for Flexibility has the following definition:
(define (close-enuf? h1 h2 tolerance)
(n:<= (n:magnitude (n:- h1 h2))
(n:* .5
...
0
votes
1
answer
77
views
One way to construct graph adjacency list based on adjacency pairs similar to `fold` in MIT Scheme
Recently when I self-learnt MIT 6.5151 course, I first read CS 61AS Unit 0 as the preparation. Then I have read SICP 1 to 2.1 (with related lecture notes) as ps0 requires (also read 2.2.1 as CS 61A ...
1
vote
2
answers
91
views
How is nested variable argument interpreted in Scheme?
The following minimal example is based on this code block:
(define (nested_var_arg . (arg_1 . args))
(if (list? args)
(begin
(displayln "args")
(displayln args))
(if (...
0
votes
0
answers
46
views
How to make the variable loaded in one loaded file available in Scheme?
I have the following directory structure (minimal demo):
main.scm
(load "regex_utils.scm")
(displayln "test")
...
regex_utils.scm
(load "utils.scm")
... ; load many ...
0
votes
1
answer
50
views
"The object square is not applicable" but `square` is one internal procedure in MIT-Scheme
Recently when I self-learnt MIT 6.5151 course, I first read CS 61AS Unit 0 as the preparation. Then I have read SICP 1 to 2.1 (with related lecture notes) as ps0 requires (also read 2.2.1 as CS 61A ...
1
vote
0
answers
43
views
How to use `reduce` with `and` in MIT-Scheme? [duplicate]
Recently when I self-learnt MIT 6.5151 course, I first read CS 61AS Unit 0 as the preparation. Then I have read SICP 1 to 2.1 (with related lecture notes) as ps0 requires (also read 2.2.1 as CS 61A ...
0
votes
0
answers
34
views
"Ill-formed syntax: (define (expmod a num num) ((exptmod num) a num))" in Scheme
I am learning SICP up to chapter 2.2.1 now. I have the following code:
(define (modular n op)
(lambda (a b)
(modulo (op a b) n)))
(define (exptmod p)
(let ((mod* (modular p *)))
(define (...