[format] add define form
This commit is contained in:
parent
f7dff260bc
commit
011ca1771c
|
@ -4,7 +4,7 @@
|
||||||
;; `format:` expressions that should fail to compile
|
;; `format:` expressions that should fail to compile
|
||||||
|
|
||||||
(module+ test (test-compile-error
|
(module+ test (test-compile-error
|
||||||
#:require trivial/format
|
#:require trivial/format trivial/define
|
||||||
#:exn #rx"format::|Type Checker"
|
#:exn #rx"format::|Type Checker"
|
||||||
(printf: "hello ~a" "john" "doe")
|
(printf: "hello ~a" "john" "doe")
|
||||||
(printf: "hello ~a" "john" "doe")
|
(printf: "hello ~a" "john" "doe")
|
||||||
|
@ -12,4 +12,9 @@
|
||||||
(printf: "character ~c\n" 88)
|
(printf: "character ~c\n" 88)
|
||||||
(printf: "octl ~o\n" 1.0+2i)
|
(printf: "octl ~o\n" 1.0+2i)
|
||||||
(printf: "hex ~o\n" (exact->inexact 0))
|
(printf: "hex ~o\n" (exact->inexact 0))
|
||||||
|
(let ()
|
||||||
|
(define: s "asdf ~a asdf")
|
||||||
|
(printf: s))
|
||||||
|
(let: ([s "asdf ~a asdf"])
|
||||||
|
(printf: s))
|
||||||
))
|
))
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
trivial/private/common
|
trivial/private/common
|
||||||
syntax/parse
|
syntax/parse
|
||||||
typed/racket/base)
|
typed/racket/base)
|
||||||
|
(only-in trivial/private/format
|
||||||
|
format-define
|
||||||
|
format-let)
|
||||||
(only-in trivial/private/math
|
(only-in trivial/private/math
|
||||||
num-define
|
num-define
|
||||||
num-let)
|
num-let)
|
||||||
|
@ -26,14 +29,16 @@
|
||||||
|
|
||||||
(define-syntax define: (make-keyword-alias 'define
|
(define-syntax define: (make-keyword-alias 'define
|
||||||
(lambda (stx)
|
(lambda (stx)
|
||||||
(or (num-define stx)
|
(or (format-define stx)
|
||||||
|
(num-define stx)
|
||||||
(rx-define stx)
|
(rx-define stx)
|
||||||
(fun-define stx)
|
(fun-define stx)
|
||||||
(vec-define stx)))))
|
(vec-define stx)))))
|
||||||
|
|
||||||
(define-syntax let: (make-keyword-alias 'let
|
(define-syntax let: (make-keyword-alias 'let
|
||||||
(lambda (stx)
|
(lambda (stx)
|
||||||
(or (fun-let stx)
|
(or (format-let stx)
|
||||||
|
(fun-let stx)
|
||||||
(num-let stx)
|
(num-let stx)
|
||||||
(rx-let stx)
|
(rx-let stx)
|
||||||
(vec-let stx)))))
|
(vec-let stx)))))
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
(provide
|
(provide
|
||||||
format:
|
format:
|
||||||
printf:
|
printf:
|
||||||
|
|
||||||
|
(for-syntax
|
||||||
|
format-define
|
||||||
|
format-let)
|
||||||
)
|
)
|
||||||
|
|
||||||
(require
|
(require
|
||||||
|
@ -59,7 +63,7 @@
|
||||||
(loop (+ i 1) acc)]))]
|
(loop (+ i 1) acc)]))]
|
||||||
[else #f]))
|
[else #f]))
|
||||||
|
|
||||||
(define-values (_key fmt? _define _let)
|
(define-values (_key fmt? format-define format-let)
|
||||||
(make-value-property 'string:format format-parser))
|
(make-value-property 'string:format format-parser))
|
||||||
|
|
||||||
(define-syntax-class/predicate string/format fmt?)
|
(define-syntax-class/predicate string/format fmt?)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user