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?
When the authors implement the mutex part of serializers, they use a list called
Share
Because a variable isn’t a first-class value that you can pass to another function. In 3.4, the authors implement a
make-mutexfunction that usesclear!as a helper function, which takes a cell. If the cell were represented by a mutable variable, thenclear!would have to be defined insidemake-mutex!to close over that variable. The same goes for thetest-and-set!helper function.They also could have used, say, a box instead of a cons cell.