5

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?

Sam Tobin-Hochstadt
  • 4,983
  • 1
  • 21
  • 43
Bin Wang
  • 2,697
  • 2
  • 24
  • 34

2 Answers2

10

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.

Asumu Takikawa
  • 8,447
  • 1
  • 28
  • 43
5

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.

pjhades
  • 1,948
  • 2
  • 19
  • 34