Skip to content

Instantly share code, notes, and snippets.

@jgreco
Created September 16, 2019 19:51
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 jgreco/e0a699bbf610ed671acf4b9d29a364f2 to your computer and use it in GitHub Desktop.
Save jgreco/e0a699bbf610ed671acf4b9d29a364f2 to your computer and use it in GitHub Desktop.
(define-syntax-parser define/with-hooks
([_ (name:id formals:id ...+)
body:expr ...+]
#'(define name (lambda (formals ...)
;; invoke pre-hooks
(for ([h (get-hooks 'name)]) (h formals ...))
(let ([result (begin body ...)])
;; invoke post-hooks
(for ([h (get-hooks 'name)]) (h result))
result)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment