Adding some def transformers

This commit is contained in:
Jay McCarthy 2015-11-24 15:09:44 -05:00
parent a5b65f285e
commit 0fbc60484d
3 changed files with 56 additions and 5 deletions

View File

@ -172,7 +172,7 @@ TODO zos don't appear to users (switch to interp if no write access)
TODO only use syntax-parse and define-simple-macro
TODO use \dots as ...
DONE use \ldots as ...
TODO add a threading macro
@ -205,9 +205,11 @@ https://github.com/greghendershott/def-jambda
DONE nest form like def* for things like parameterize that would look
weird as def* transformers
TODO stx def transfomer
DONE stx def transfomer
TODO mac def transformer (simple-macro)
TODO fun def transformer
DONE mac def transformer (simple-macro)
TODO mac def+ transformer (syntax-parser)

View File

@ -15,7 +15,6 @@
(define-syntax (def stx)
(syntax-parse stx
#:literals (#%brackets)
;; xxx test this
[(_ (#%brackets dt . _) . _)
#:declare dt (static def-transformer? "def transformer")
(def-transform (attribute dt.value) stx)]
@ -301,6 +300,7 @@
binary-operator-precedence)
#%dot
(for-syntax gen:dot-transformer)
(rename-out [... ])
#%app
#%datum
quote
@ -311,6 +311,19 @@
for-syntax
provide)
(define-syntax val
(singleton-struct
#:property prop:procedure
(λ (stx)
(raise-syntax-error 'val "Illegal outside def" stx))
#:methods gen:def-transformer
[(define (def-transform _ stx)
(syntax-parse stx
#:literals (#%brackets)
[(_def (#%brackets _stx x:id) . body:expr)
(syntax/loc stx
(define x (remix-block . body)))]))]))
(define-syntax stx
(singleton-struct
#:property prop:procedure
@ -324,4 +337,19 @@
(syntax/loc stx
(define-syntax x (remix-block . body)))]))]))
(provide stx)
(define-syntax mac
(singleton-struct
#:property prop:procedure
(λ (stx)
(raise-syntax-error 'mac "Illegal outside def" stx))
#:methods gen:def-transformer
[(define (def-transform _ stx)
(syntax-parse stx
#:literals (#%brackets)
[(_def (#%brackets _mac (x:id . pat:expr)) . body:expr)
(syntax/loc stx
(define-simple-macro (x . pat) . body))]))]))
(provide val
stx
mac)

View File

@ -187,5 +187,26 @@
{(f-rest-args 1) 42}
{(f-rest-args 1 2 3) 42})
;; def supports a variety of "def transformers" that change from
;; defining a phase-0 value to something else.
;; val ensures that a function is NOT defined
(def [val v99] 99)
(module+ test
{v99 99})
;; stx is define-syntax
(require (for-syntax remix/stx0))
(def [stx stx42] 42)
;; mac is define-simple-macro
(def [mac (flip f x y)]
(f y x))
(module+ test
{(flip - 5 0) (- 0 5)})
;; … (\ldots) is ... (because that doesn't work with cdots)
(def [mac (flipper f x y)]
(f y x ))
(module+ test
{(flipper - 5 9 0) (- 0 5 9)})