Skip to content

Instantly share code, notes, and snippets.

Created Oct 14, 2011
What would you like to do?
(use gauche.threads)
(define (runonce fn)
(let1 state (atom #f) ; once run, becomes (list result)
(values (^[] (atomic state boolean)) ;has-run?
(^[] (atomic-update! state (^_ #f))) ;reset
(^ args ;once
(car (atomic-update! state (^p (or p `(,(apply fn args))))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment