Merged in make-var-like-trans (pull request #1)
add version of make-variable-like-transformer
This commit is contained in:
commit
a3831adae2
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
compiled/
|
||||
doc/
|
||||
*~
|
|
@ -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))
|
||||
|
||||
|
|
|
@ -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))])))
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user