Page:Scheme - An interpreter for extended lambda calculus.djvu/5

  This is the synchronization primitive. It evaluates an expression uninterruptibly; i.e. no other process may run until the expression has returned a value. Note that if a  is returned from the scope of an , then that   will be uninterruptible when it is applied; that is, the uninterruptibility property follows the rules of variable scoping. For example, consider the following function:

This returns a pair of functions which are V and P operations on a newly created semaphore. The argument to  is the initial value for the semaphore. Note that P busy-waits by iterating if necessary; because  uses variable-scoping rules, other processes have a chance to get in at the beginning of each iteration. This busy-wait can be made much more efficient by replacing the expression  in the definition of   with

Let's see you figure this one out! Note that a  within an   forces the process to be swapped out even if it is the current one, and so other processes get to run; but as soon as it gets swapped in again, others are locked out as before.  

Besides the s, SCHEME has a class of primitives known as  s. These are similar to MacLISP  s, in that they are expanded into equivalent code before being executed. Some s supplied with the SCHEME interpreter:     This is like the MacLISP  statement, except that singleton clauses (where the result of the predicate is the returned value) are not allowed.  ,   These are also as in MacLISP.  