diff --git a/format.rkt b/format.rkt index c0e0361..49ac936 100644 --- a/format.rkt +++ b/format.rkt @@ -40,11 +40,17 @@ (if t (quasisyntax/loc #'f (ann #,a #,t)) a))]) (quasisyntax/loc #'f (format template #,@arg+*))))] + [f:id + (syntax/loc #'f format)] [(f tmp arg* ...) (syntax/loc #'f (format tmp arg* ...))])) -(define-syntax-rule (printf: arg* ...) - (display (format: arg* ...))) +(define-syntax printf: + (syntax-parser + [f:id + (syntax/loc #'f printf)] + [(f arg* ...) + (syntax/loc #'f (display (format: arg* ...)))])) ;; ----------------------------------------------------------------------------- diff --git a/test/format/pass.rkt b/test/format/pass.rkt index 9ddc9f8..a7b857e 100644 --- a/test/format/pass.rkt +++ b/test/format/pass.rkt @@ -39,4 +39,16 @@ (parameterize ([error-print-width 4]) (test-format: ["~a ~.a" "hello" "world"] "hello w...")) + ;; Higher-order use: should work, but lose typechecking + (check-equal? + ((lambda ([f : (-> String Any String)] [x : Any]) (f "hello ~a" x)) + format: 'world) + "hello world") + + (check-exn exn:fail:contract? + (lambda () + ((lambda ([f : (-> String Any Void)]) + (f "~b" "not-a-number")) + printf:))) + )