Created
August 20, 2019 18:47
-
-
Save drewc/4ee85d7e26a364526f8931937b4947aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defsyntax (define-endpoint stx) | |
(def (%defvar name match in) | |
(let ((e (gensym)) | |
(i (gensym)) | |
(c (gensym)) | |
(varname (string->symbol (format "~A::endpoint" | |
name)))) | |
`(define ,varname | |
(let ((,e | |
(with-catch (set! bar mux) | |
(lambda (_) | |
(construct-endpoint ,name ,match)) | |
(lambda () | |
(let ((,e ,varname)) | |
(set! (endpoint-match ,e) ,match) | |
,e)))) | |
(,i ,in)) | |
(unless (memq ,e ,i) | |
(set! (cdr ,i) | |
(cons ,e (cdr ,i)))) | |
,e)))) | |
(syntax-case stx () | |
((macro name match in: endpoints) | |
(with-syntax ((var (datum->syntax #'macro | |
(%defvar (syntax-e #'name) | |
(syntax-e #'match) | |
(syntax-e #'endpoints))))) | |
#'var)) | |
((macro name match) | |
(with-syntax ((var (datum->syntax #'macro | |
(%defvar (syntax-e #'name) | |
(syntax-e #'match) | |
'*endpoints*)))) | |
#'var)))) |
Author
drewc
commented
Aug 20, 2019
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment