Modularity, Objects, and State
50 questions available
Questions
In the context of programming with local state, what does it mean for an object to 'have state'?
View answer and explanationGiven 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);`?
View answer and explanationWhat is the primary conceptual cost or disadvantage of introducing assignment into a programming language, as discussed in section 3.1.3?
View answer and explanationIn the environment model of evaluation, what does a function object consist of?
View answer and explanationWhat is the primary purpose of the `set_head` and `set_tail` operations introduced in Section 3.3.1?
View answer and explanationA queue is described as a FIFO buffer. What does FIFO stand for?
View answer and explanationIn the efficient queue implementation in Section 3.3.2, how is a queue represented to allow for constant-time (Theta(1)) insertions?
View answer and explanationWhat 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`?
View answer and explanationWhat is the function of a 'serializer' as introduced in Section 3.4.2?
View answer and explanationIn the context of the digital circuit simulator, what are the three primitive operations on wires used to build function boxes?
View answer and explanationHow does the stream-based approach to modeling state differ from the assignment-based approach?
View answer and explanationWhat is the key mechanism that allows streams to represent very long or infinite sequences efficiently without constructing them all at once?
View answer and explanationWhat 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?
View answer and explanationWhat happens in the environment model when a function is applied to a set of arguments?
View answer and explanationIn the `make_account` function from Section 3.1.1, how are the `withdraw` and `deposit` functions able to access and modify the `balance` variable?
View answer and explanationA situation where a single computational object can be accessed by more than one name is known as what?
View answer and explanationIn the Monte Carlo simulation to estimate pi, what is the mathematical fact that the `dirichlet_test` function is based on?
View answer and explanationWhat 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");`?
View answer and explanationIn the digital circuit simulator, what is the specified delay for an `and_gate` in the sample simulation of Section 3.3.4?
View answer and explanationWhat is a 'deadlock' in the context of concurrent programming?
View answer and explanationWhat does the stream `const integers = pair(1, () => add_streams(ones, integers));` represent?
View answer and explanationAccording 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?
View answer and explanationWhat is the key insight of the `interleave` function that allows `pairs(integers, integers)` to eventually generate all pairs of integers, unlike `stream_append`?
View answer and explanationIn 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?
View answer and explanationWhat problem does the normal-order evaluation model solve that is present in the delayed-stream model of Section 3.5.4?
View answer and explanationIn 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?
View answer and explanationWhat is the result of evaluating `const z1 = pair(x, x);` where `const x = list("a", "b");` followed by `set_head(head(z1), "wow");`?
View answer and explanationIn the table implementation from Section 3.3.3, what is the role of the dummy record `"*table*"` at the beginning of the headed list?
View answer and explanationWhat 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); }`?
View answer and explanationWhat is the term for a programming style that makes extensive use of assignment?
View answer and explanationIn 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);`?
View answer and explanationWhat 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?
View answer and explanationIn the context of the `make_account` function from exercise 3.3 that is password-protected, where is the password stored?
View answer and explanationWhat does a 'mutex' object, as described in Section 3.4.2, support?
View answer and explanationIn the functional implementation of mutable pairs in Section 3.3.1, how is a pair represented?
View answer and explanationWhat is the key problem with the simple `count_pairs` function written by Ben Bitdiddle in Exercise 3.16?
View answer and explanationIn the lazy evaluator, what is a 'thunk'?
View answer and explanationWhat is the primary benefit of memoizing thunks in a lazy evaluator, as mentioned in Section 4.2.2?
View answer and explanationWhat 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`?
View answer and explanationWhat is the fundamental problem with using `stream_append` to combine two infinite streams?
View answer and explanationIn the concurrent `exchange` function example, what is the purpose of acquiring serializers for both accounts involved in the transaction?
View answer and explanationGiven 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`?
View answer and explanationWhat is the fundamental difference between the `integers_starting_from` stream function and the `an_integer_starting_from` amb function?
View answer and explanationIn the `solve` function for differential equations in Section 3.5.4, why is the `dy` argument to `integral` written as `() => dy`?
View answer and explanationWhat 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)`?
View answer and explanationIn the `count_pairs` function from Exercise 3.16, for which structure would the function never return a value?
View answer and explanationIn the stream formulation of the Monte Carlo estimation of pi in Section 3.5.5, how are better estimates of pi obtained?
View answer and explanationIf 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?
View answer and explanationHow does the `make_tableau` function in Section 3.5.3 generate a 'stream of streams'?
View answer and explanationWhat 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?
View answer and explanation