Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当作者实现序列化程序的互斥部分时,他们使用了一个名为cell. 但是列表只包含一个元素,那么为什么不只使用一个变量呢?
cell
因为变量不是您可以传递给另一个函数的一等值。在 3.4 中,作者实现了一个make-mutex用作clear!辅助函数的函数,该函数接受一个单元格。如果单元格由可变变量表示,则clear!必须在内部定义make-mutex!以关闭该变量。test-and-set!辅助函数也是如此。
make-mutex
clear!
make-mutex!
test-and-set!
他们也可以使用,比如说,一个盒子而不是一个缺点单元。
如果在那里使用变量而不是列表,则过程将不起作用,因为 Scheme 是按值传递的clear!。test-and-set!