From bea91f647d0689ad939c19bc9f4d1dce91967ad4 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sat, 26 Feb 2022 16:12:38 -0800 Subject: [PATCH] shorten kws --- quad/quad2/atomize.rkt | 4 ++-- quad/quad2/compile.rkt | 20 +++++++++++--------- quad/quad2/draw.rkt | 8 ++++---- quad/quad2/layout.rkt | 4 ++-- quad/quad2/main.rkt | 4 ++-- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/quad/quad2/atomize.rkt b/quad/quad2/atomize.rkt index e1306b9d..1b748045 100644 --- a/quad/quad2/atomize.rkt +++ b/quad/quad2/atomize.rkt @@ -16,8 +16,8 @@ that will eventually be the tail of the attrs in every atomized quad. |# (define-pass (atomize q) - #:precondition quad? - #:postcondition (list-of quad?) + #:pre quad? + #:post (list-of quad?) (match (quad-elems q) [(cons str _) (for/list ([c (in-string str)]) diff --git a/quad/quad2/compile.rkt b/quad/quad2/compile.rkt index b911c980..e0fe04b7 100644 --- a/quad/quad2/compile.rkt +++ b/quad/quad2/compile.rkt @@ -16,14 +16,16 @@ (make-compiler (append (compiler-passes c) passes))) (define-syntax-rule (define-pass (PASS-NAME ARG OTHER-ARG ...) - #:precondition PRECOND-PROC - #:postcondition POSTCOND-PROC + #:pre PRECOND-PROC + #:post POSTCOND-PROC EXPRS ...) (define PASS-NAME - (make-compiler (list (λ (ARG OTHER-ARG ...) - (unless (PRECOND-PROC ARG) - (error 'PASS-NAME (format "precondition failed: ~a for value ~v" 'PRECOND-PROC ARG))) - (define res (let () EXPRS ...)) - (unless (POSTCOND-PROC res) - (error 'PASS-NAME (format "postcondition failed: ~a for value ~v" 'POSTCOND-PROC res))) - res))))) \ No newline at end of file + (make-compiler + (list (procedure-rename + (λ (ARG OTHER-ARG ...) + (unless (PRECOND-PROC ARG) + (raise-argument-error 'PASS-NAME (format "~a" 'PRECOND-PROC) ARG)) + (define res (let () EXPRS ...)) + (unless (POSTCOND-PROC res) + (raise-argument-error 'PASS-NAME (format "~a" 'POSTCOND-PROC) res)) + res) 'PASS-NAME))))) \ No newline at end of file diff --git a/quad/quad2/draw.rkt b/quad/quad2/draw.rkt index 7346430a..cd65976d 100644 --- a/quad/quad2/draw.rkt +++ b/quad/quad2/draw.rkt @@ -10,8 +10,8 @@ (provide (all-defined-out)) (define-pass (make-drawing-insts qs) - #:precondition (list-of has-position?) - #:postcondition (list-of $drawing-inst?) + #:pre (list-of has-position?) + #:post (list-of $drawing-inst?) (flatten (list ($doc 'start) ($page 'start) (for/list ([q (in-list qs)]) @@ -24,8 +24,8 @@ (define valid-tokens '(doc-start doc-end page-start page-end text move)) (define-pass (stackify xs) - #:precondition (λ (xs) (and (list? xs) (andmap $drawing-inst? xs))) - #:postcondition string? + #:pre (list-of $drawing-inst?) + #:post string? (define move-points (map $move-posn (filter $move? xs))) (define xmax (add1 (apply max (map $point-x move-points)))) (define ymax (add1 (apply max (map $point-y move-points)))) diff --git a/quad/quad2/layout.rkt b/quad/quad2/layout.rkt index 64bb0403..6595bc1e 100644 --- a/quad/quad2/layout.rkt +++ b/quad/quad2/layout.rkt @@ -36,8 +36,8 @@ (rect-contains-point? outer ($point (max-x inner) (max-y inner))))) (define-pass (layout qs) - #:precondition (list-of has-no-position?) - #:postcondition (list-of has-position?) + #:pre (list-of has-no-position?) + #:post (list-of has-position?) (define frame ($rect ($point 0 0) ($size (current-wrap-width) 30))) (define (quad-fits? q posn) (define q-size (size q)) diff --git a/quad/quad2/main.rkt b/quad/quad2/main.rkt index 5f6c1dcc..99782c00 100644 --- a/quad/quad2/main.rkt +++ b/quad/quad2/main.rkt @@ -10,8 +10,8 @@ racket/match) (define-pass (bootstrap x) - #:precondition values - #:postcondition quad? + #:pre values + #:post quad? (match x [(or (? quad? q) (list (? quad? q))) q] [(and (list (? quad?) ...) qs) (make-quad #:elems qs)]