Added opt-lambda:.

This commit is contained in:
Vincent St-Amour 2010-08-04 15:52:41 -04:00
parent 0b3c637f5d
commit 4cb7491309
2 changed files with 37 additions and 0 deletions

View File

@ -63,3 +63,25 @@
(~or rest:annotated-star-rest rest:annotated-dots-rest)))
#:with ann-formals #'(n.ann-name ... . rest.ann-name)
#:with (arg-ty ...) #'(n.ty ... . rest.formal-ty)))
(define-syntax-class opt-lambda-annotated-formal
#:description "annotated variable, potentially with a default value"
#:opaque
#:attributes (name ty ann-name)
(pattern [:annotated-name])
(pattern [n:annotated-name val]
#:with name #'n.name
#:with ty #'n.name
#:with ann-name #'(n.ann-name val)))
(define-syntax-class opt-lambda-annotated-formals
#:attributes (ann-formals (arg-ty 1))
#:literals (:)
(pattern (n:opt-lambda-annotated-formal ...)
#:with ann-formals #'(n.ann-name ...)
#:with (arg-ty ...) #'(n.ty ...))
(pattern (n:opt-lambda-annotated-formal ...
(~describe "dotted or starred type"
(~or rest:annotated-star-rest rest:annotated-dots-rest)))
#:with ann-formals #'(n.ann-name ... . rest.ann-name)
#:with (arg-ty ...) #'(n.ty ... . rest.formal-ty)))

View File

@ -27,6 +27,7 @@ This file defines two sorts of primitives. All of them are provided into any mod
(require "../utils/utils.rkt"
racket/base
mzlib/etc
(for-syntax
syntax/parse
syntax/private/util
@ -173,6 +174,15 @@ This file defines two sorts of primitives. All of them are provided into any mod
'typechecker:plambda
#'(tvars ...))))]))
(define-syntax (popt-lambda: stx)
(syntax-parse stx
[(popt-lambda: (tvars:id ...) formals . body)
(quasisyntax/loc stx
(#%expression
#,(syntax-property (syntax/loc stx (opt-lambda: formals . body))
'typechecker:plambda
#'(tvars ...))))]))
(define-syntax (pdefine: stx)
(syntax-parse stx #:literals (:)
[(pdefine: (tvars:id ...) (nm:id . formals:annotated-formals) : ret-ty . body)
@ -223,6 +233,11 @@ This file defines two sorts of primitives. All of them are provided into any mod
[(case-lambda: [formals:annotated-formals . body] ...)
(syntax/loc stx (case-lambda [formals.ann-formals . body] ...))]))
(define-syntax (opt-lambda: stx)
(syntax-parse stx
[(opt-lambda: formals:opt-lambda-annotated-formals . body)
(syntax/loc stx (opt-lambda formals.ann-formals . body))]))
(define-syntaxes (let-internal: let*: letrec:)
(let ([mk (lambda (form)
(lambda (stx)