Skip to content

Instantly share code, notes, and snippets.

@kragen
Created August 22, 2012 20:43
Show Gist options
  • Save kragen/3429195 to your computer and use it in GitHub Desktop.
Save kragen/3429195 to your computer and use it in GitHub Desktop.
A CoffeeScript and corrected version of https://gist.github.com/3428922.
# CoffeeScript version of voting code from
# <http://www.cap-lore.com/CapTheory/Language/lambdaSecurity.html>:
mocntr = ->
x = 0
voterMaker: ->
yet = true
-> if yet
yet = false
++x
votes: -> x
restaurants = ["Mandarin", "Casa Lupe", "Coffee Shop"]
lunchCrowd = ['Jim', 'Sue', 'Tom', 'Jennifer'];
lunchAgents =
for eater in lunchCrowd
(->
cell = eater: eater
SEND eater, "LunchAgentAppointer", (agent) -> cell.agent = agent
cell)()
noontime = ->
bb = for restaurant in restaurants
restaurant: restaurant
counter: mocntr()
for e in lunchAgents
e.agent "Lunchtime!",
for r in bb
restaurant: r.restaurant
vote: r.voterMaker()
-> for r in bb
restaurant: r.restaurant
votes: r.counter.votes()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment