(define (mocntr) (let ((x 0)) (cons (lambda () (let ((yet #t))First a comment about the formatting: I don’t know how to format such programs to suit either myself or any current program æsthetics. To read my own code I must use an interactive editor that balances parentheses.
(lambda () (if yet (begin (set! yet #f) (set! x (+ 1 x)) x)))))
(lambda () x))))
(define lunchcrowd (list (lambda (x) (write (cons "for Bill" x)))
(lambda (x) (write (cons "for Bob" x))
((cdr (assoc "Mandarin" (cdr x)))))))
(define restaurants (list "Mandarin" "Casa Lupe" "Coffee Shop"))
(define (noontime) (let ((bb
(map (lambda(r) (cons r (mocntr))) restaurants)))
(for-each (lambda (e) (e (cons "Lunchtime!" (map
(lambda(r)(cons (car r) ((cadr r)))) bb)))) lunchcrowd)
(lambda ()(map (lambda(x) (cons (car x) ((cddr x)))) bb))))
When it is time to decide the Scheme command (res) from the instigator’s terminal, reports the results of the voting.
The code above is fake in that the procs in lunchcrowd would in practice be constructed by the various diners and somehow those procs would invoke the eater and not merely some caned procedure. Bob, on the other hand, seems to have cast a permanent vote for Mandarin. This illustrates that much of the rest of the code actually runs!
bb is created each day for lunch and constitutes the ballot box. It is a list of pairs <restuarant name, <option source, count getter>>. This list is iterated over first to send each vote solicitation, and then later to count the votes.
(("Mandarin" . 1) ("Casa Lupe" . 0) ("Coffee Shop" . 0))
The code as it stands solicits a vote only after it records the previous vote—serial voting.
Scheme needs to address concurrency and to support atomic actions such as (set! x (+ 1 x)). The language Actors does all of this nicely I think but I have no implementation of Actors. I suppose that Java can do this but with much more ocde.
This shows problems with garbage collection that are germane to an OS. If one of the lunch crowd is away for several days his options persist for no purpose. In Keykos and I presume Eros, the instigator can reclaim all space after they are back from lunch, even though there may remain references.