When the authors implement the mutex part of serializers, they use a list called cell
. But the list only contains one element, so why not just use a variable?
Because a variable isn't a first-class value that you can pass to another function. In 3.4, the authors implement a make-mutex
function that uses clear!
as a helper function, which takes a cell. If the cell were represented by a mutable variable, then clear!
would have to be defined inside make-mutex!
to close over that variable. The same goes for the test-and-set!
helper function.
They also could have used, say, a box instead of a cons cell.
If a variable is used there instead of a list, the procedures clear!
and test-and-set!
won't work since Scheme is pass-by-value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With