(raise-syntax-error'define-cases"definition of a syntax transformer must use lambda notation, because otherwise it's too easy to confuse the compile-time shape and the run-time shape"(syntax->datum#'sid.name))]
;; syntax matcher
[(_top-id:syntaxed-id[(syntaxpat)body...]...+)
#'(define-syntaxtop-id.name(λ(stx)
(defineresult
(syntax-casestx()
[patbody...]...
[else(raise-syntax-error'define-cases(format"no matching case for syntax pattern `~a`"(syntax->datumstx))(syntax->datum#'top-id.name))]))
(if(not(syntax?result))
(datum->syntaxstxresult)
result)))]
;; function matcher
[(_top-id:id[(_pat-arg....rest-arg)body...]...)
#'(definetop-id
(case-lambda
[(pat-arg....rest-arg)body...]...
[else(raise-syntax-error'define-cases"no matching case for argument pattern"(object-nametop-id))]))]))
(raise-syntax-error'define"definition of a syntax transformer must use lambda notation, because otherwise it's too easy to confuse the compile-time shape and the run-time shape"(syntax->datum#'sid.name))]
(raise-syntax-error'define"definition of a syntax transformer must use lambda notation, because otherwise it's too easy to confuse the compile-time shape and the run-time shape"(syntax->datum#'sid.name))]
@ -69,63 +114,53 @@
(module+test
(module+test
(requirerackunit)
(requirerackunit)
(br:define#'plus(λ(stx)#'+))
(br:define#'plus(λ(stx)#'+))
(br:define#'plusser#'plus)
(br:define#'(timesarg)#'(*argarg))
(br:define#'timeser#'times)
(br:define#'fortytwo#'42)
(check-equal?(plus42)+)
(check-equal?(plus42)+)
(check-equal? plusser+)
(br:define#'plusser#'plus)
(check-equal?(plusser42)+)
(check-equal?(plusser42)+)
(check-equal?plusser+)
(br:define#'(timesarg)#'(*argarg))
(check-equal?(times10)100)
(check-equal?(times10)100)
(br:define#'timeser#'times)
(check-equal?(timeser12)144)
(check-equal?(timeser12)144)
(br:define#'fortytwo#'42)
(check-equal?fortytwo42)
(check-equal?(let()
(check-equal?(let()
(br:define#'(foox)
(br:define#'(foox)
(with-syntax([zam+])
(with-syntax([zam+])
#'(zamxx)))(foo42))84)
#'(zamxx)))(foo42))84)
;; todo: error from define not trapped by check-exn
;; todo: error from define not trapped by check-exn