Pauan

Python-style Generators in Arc

Jan 14th, 2012
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. (= fail (uniq))
  2.  
  3. (def make-gen (f)
  4. (withs (next nil
  5. exit nil
  6. yield (fn (val)
  7. (ccc (fn (c)
  8. (= next c)
  9. (exit val)))))
  10. (fn args
  11. (ccc (fn (c)
  12. (if next (next args)
  13. (do (= exit c)
  14. (f yield)
  15. fail)))))))
  16.  
  17. (mac gen body
  18. `(make-gen (fn (yield) ,@body)))
Advertisement
Add Comment
Please, Sign In to add comment