once.scm 587 B

123456789101112131415161718192021222324252627
  1. (import
  2. (except (rnrs base) map)
  3. (only (guile)
  4. lambda* λ
  5. unless))
  6. (define-syntax once!
  7. (λ (stx)
  8. (syntax-case stx ()
  9. [(once! exprs ... flag)
  10. (syntax
  11. (unless flag
  12. exprs ...
  13. (set! flag #t)))])))
  14. (define already-happened #f)
  15. (once! (simple-format (current-output-port) "~a\n" "This should only work once.")
  16. (simple-format (current-output-port) "~a\n" "With this second message.")
  17. already-happened)
  18. (once! (simple-format (current-output-port) "~a\n" "This should only work once.")
  19. already-happened)