In the `count_pairs` function from Exercise 3.16, for which structure would the function never return a value?

Correct answer: A cyclic list, such as one created by `make_cycle`.

Explanation

This question assesses the understanding of how simple recursive traversal algorithms can fail catastrophically when applied to data structures with cycles, a common pitfall with mutable data.

Other questions

Question 1

In the context of programming with local state, what does it mean for an object to 'have state'?

Question 2

Given the function `const W1 = make_withdraw(100);`, what is the sequence of returned values from the following successive calls: `W1(50);`, `W2(70);`, `W2(40);`, `W1(40);` where `const W2 = make_withdraw(100);`?

Question 3

What is the primary conceptual cost or disadvantage of introducing assignment into a programming language, as discussed in section 3.1.3?

Question 4

In the environment model of evaluation, what does a function object consist of?

Question 5

What is the primary purpose of the `set_head` and `set_tail` operations introduced in Section 3.3.1?

Question 6

A queue is described as a FIFO buffer. What does FIFO stand for?

Question 7

In the efficient queue implementation in Section 3.3.2, how is a queue represented to allow for constant-time (Theta(1)) insertions?

Question 8

What is the primary problem that arises in concurrent programming when two threads, such as Peter's and Paul's withdrawals, attempt to modify a shared variable like `balance`?

Question 9

What is the function of a 'serializer' as introduced in Section 3.4.2?

Question 10

In the context of the digital circuit simulator, what are the three primitive operations on wires used to build function boxes?

Question 11

How does the stream-based approach to modeling state differ from the assignment-based approach?

Question 12

What is the key mechanism that allows streams to represent very long or infinite sequences efficiently without constructing them all at once?

Question 13

What is the result of evaluating `stream_ref(primes, 50);` where `primes` is the stream of prime numbers generated by the sieve of Eratosthenes as defined in Section 3.5.2?

Question 14

What happens in the environment model when a function is applied to a set of arguments?

Question 15

In the `make_account` function from Section 3.1.1, how are the `withdraw` and `deposit` functions able to access and modify the `balance` variable?

Question 16

A situation where a single computational object can be accessed by more than one name is known as what?

Question 17

In the Monte Carlo simulation to estimate pi, what is the mathematical fact that the `dirichlet_test` function is based on?

Question 18

What is the result of applying the `mystery` function from Exercise 3.14 to the list `v` defined as `const v = list("a", "b", "c", "d");`?

Question 19

In the digital circuit simulator, what is the specified delay for an `and_gate` in the sample simulation of Section 3.3.4?

Question 20

What is a 'deadlock' in the context of concurrent programming?

Question 21

What does the stream `const integers = pair(1, () => add_streams(ones, integers));` represent?

Question 22

According to the Euler transform for accelerating sequence convergence, if `s0`, `s1`, and `s2` are three consecutive terms in a stream, what is the corresponding term in the transformed sequence?

Question 23

What is the key insight of the `interleave` function that allows `pairs(integers, integers)` to eventually generate all pairs of integers, unlike `stream_append`?

Question 24

In the stream-based model of an RC circuit in Exercise 3.73, what does the feedback loop in the signal-flow diagram correspond to in the `integral` function's definition?

Question 25

What problem does the normal-order evaluation model solve that is present in the delayed-stream model of Section 3.5.4?

Question 26

In the imperative version of the factorial function in Section 3.1.3, why is the order of the two assignment statements `product = counter * product;` and `counter = counter + 1;` critical?

Question 27

What is the result of evaluating `const z1 = pair(x, x);` where `const x = list("a", "b");` followed by `set_head(head(z1), "wow");`?

Question 28

In the table implementation from Section 3.3.3, what is the role of the dummy record `"*table*"` at the beginning of the headed list?

Question 29

What is the fundamental flaw in Louis Reasoner's proposed `squarer` constraint from Exercise 3.34, defined as `function squarer(a, b) { return multiplier(a, a, b); }`?

Question 30

What is the term for a programming style that makes extensive use of assignment?

Question 31

In the `make_monitored` function from Exercise 3.2, if you create `const s = make_monitored(math_sqrt);`, what is the returned value of a second call to `s("how many calls");` after an initial call of `s(100);`?

Question 32

What is the mechanism that allows local functions within the `sqrt` function (e.g., `is_good_enough`) to access the argument `x` of the enclosing `sqrt` function?

Question 33

In the context of the `make_account` function from exercise 3.3 that is password-protected, where is the password stored?

Question 34

What does a 'mutex' object, as described in Section 3.4.2, support?

Question 35

In the functional implementation of mutable pairs in Section 3.3.1, how is a pair represented?

Question 36

What is the key problem with the simple `count_pairs` function written by Ben Bitdiddle in Exercise 3.16?

Question 37

In the lazy evaluator, what is a 'thunk'?

Question 38

What is the primary benefit of memoizing thunks in a lazy evaluator, as mentioned in Section 4.2.2?

Question 39

What is the value of `sum` after executing `stream_ref(y, 7);` given the definitions in Exercise 3.52, where `seq` is a stream mapping `accum` over integers 1 to 20, and `y` is the stream of even numbers from `seq`?

Question 40

What is the fundamental problem with using `stream_append` to combine two infinite streams?

Question 41

In the concurrent `exchange` function example, what is the purpose of acquiring serializers for both accounts involved in the transaction?

Question 42

Given the initial values `s0 = 4`, `s1 = 2.666...`, and `s2 = 3.466...` from the `pi_stream`, what is the first value produced by `euler_transform`?

Question 43

What is the fundamental difference between the `integers_starting_from` stream function and the `an_integer_starting_from` amb function?

Question 44

In the `solve` function for differential equations in Section 3.5.4, why is the `dy` argument to `integral` written as `() => dy`?

Question 45

What is the value of the `balance` variable in the `make_simplified_withdraw(25)` example after the first call `W(20)` and the second call `W(10)`?

Question 47

In the stream formulation of the Monte Carlo estimation of pi in Section 3.5.5, how are better estimates of pi obtained?

Question 48

If Peter's and Paul's joint account starts with 100 dollars, and Peter concurrently deposits 40 dollars while Paul withdraws half the money, what are the two possible correct final balances assuming the operations are correctly serialized?

Question 49

How does the `make_tableau` function in Section 3.5.3 generate a 'stream of streams'?

Question 50

What is the primary modularity benefit of using the `rand` function with hidden local state, compared to passing the state explicitly as in the `random_gcd_test` example?