[format] add define form

This commit is contained in:
ben 2016-03-20 00:26:47 -04:00
parent f7dff260bc
commit 011ca1771c
3 changed files with 18 additions and 4 deletions

View File

@ -4,7 +4,7 @@
;; `format:` expressions that should fail to compile
(module+ test (test-compile-error
#:require trivial/format
#:require trivial/format trivial/define
#:exn #rx"format::|Type Checker"
(printf: "hello ~a" "john" "doe")
(printf: "hello ~a" "john" "doe")
@ -12,4 +12,9 @@
(printf: "character ~c\n" 88)
(printf: "octl ~o\n" 1.0+2i)
(printf: "hex ~o\n" (exact->inexact 0))
(let ()
(define: s "asdf ~a asdf")
(printf: s))
(let: ([s "asdf ~a asdf"])
(printf: s))
))

View File

@ -11,6 +11,9 @@
trivial/private/common
syntax/parse
typed/racket/base)
(only-in trivial/private/format
format-define
format-let)
(only-in trivial/private/math
num-define
num-let)
@ -26,14 +29,16 @@
(define-syntax define: (make-keyword-alias 'define
(lambda (stx)
(or (num-define stx)
(or (format-define stx)
(num-define stx)
(rx-define stx)
(fun-define stx)
(vec-define stx)))))
(define-syntax let: (make-keyword-alias 'let
(lambda (stx)
(or (fun-let stx)
(or (format-let stx)
(fun-let stx)
(num-let stx)
(rx-let stx)
(vec-let stx)))))

View File

@ -5,6 +5,10 @@
(provide
format:
printf:
(for-syntax
format-define
format-let)
)
(require
@ -59,7 +63,7 @@
(loop (+ i 1) acc)]))]
[else #f]))
(define-values (_key fmt? _define _let)
(define-values (_key fmt? format-define format-let)
(make-value-property 'string:format format-parser))
(define-syntax-class/predicate string/format fmt?)