Merged in make-var-like-trans (pull request #1)

add version of make-variable-like-transformer
This commit is contained in:
stchang 2015-09-21 18:16:40 -04:00
commit a3831adae2
3 changed files with 21 additions and 8 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
compiled/
doc/
*~

View File

@ -29,13 +29,8 @@
#;(define-syntax op/tc (make-rename-transformer (assign-type #'op #'τ)))
; rename transformer doesnt seem to expand at the right time
; - op still has no type in #%app
(define-syntax (op/tc stx)
(syntax-parse stx
[f:id ( #,(syntax/loc stx op) : τ)] ; HO case
[(o . rst)
#:with app (datum->syntax #'o '#%app)
#:with opp (format-id #'o "~a" #'op)
(syntax/loc stx (app opp . rst))])))]))
(define-syntax op/tc
(make-variable-like-transformer (assign-type #'op #'τ))))]))
(define-primop + : ( Int Int Int))

View File

@ -47,4 +47,19 @@
(define (stx-append stx1 stx2)
(append (if (syntax? stx1) (syntax->list stx1) stx1)
(if (syntax? stx2) (syntax->list stx2) stx2)))
(if (syntax? stx2) (syntax->list stx2) stx2)))
;; based on make-variable-like-transformer from syntax/transformer,
;; but using (#%app id ...) instead of ((#%expression id) ...)
(define (make-variable-like-transformer ref-stx)
(unless (syntax? ref-stx)
(raise-type-error 'make-variable-like-transformer "syntax?" ref-stx))
(lambda (stx)
(syntax-case stx ()
[id
(identifier? #'id)
ref-stx]
[(id . args)
(let ([stx* (list* '#%app #'id (cdr (syntax-e stx)))])
(datum->syntax stx stx* stx))])))