Skip to content

Instantly share code, notes, and snippets.

@shirok
Created October 14, 2011 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirok/1286756 to your computer and use it in GitHub Desktop.
Save shirok/1286756 to your computer and use it in GitHub Desktop.
(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