From ccbdb60ddf174239588938f72352ebb71c325af0 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 17 Feb 2014 19:53:28 -0800 Subject: [PATCH] tweakage --- coerce.rkt | 2 +- container.rkt | 18 +++++++++--------- define.rkt | 5 ++++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/coerce.rkt b/coerce.rkt index f6df0cd..d3f6a12 100644 --- a/coerce.rkt +++ b/coerce.rkt @@ -5,7 +5,7 @@ (define (make-coercion-error-handler target-format x) - (λ(e) (error (format "Can't convert ~a to ~a" x target-format)))) + (λ(e) (error (format "Can’t convert ~a to ~a" x target-format)))) ;; general way of coercing to integer (define+provide/contract (->int x) diff --git a/container.rkt b/container.rkt index 788908f..ff99d2f 100644 --- a/container.rkt +++ b/container.rkt @@ -56,12 +56,12 @@ ;; put item as first arg so function can use infix notation ;; (item . in . container) (define/contract (in? item container) - (any/c any/c . -> . boolean?) - (->boolean (cond - [(list? container) (member item container)] ; returns #f or sublist beginning with item - [(vector? container) (vector-member item container)] ; returns #f or zero-based item index - [(hash? container) - (and (hash-has-key? container item) (get container item))] ; returns #f or hash value - [(string? container) ((->string item) . in? . (map ->string (string->list container)))] ; returns #f or substring beginning with item - [(symbol? container) ((->string item) . in? . (->string container))] ; returns #f or subsymbol (?!) beginning with item - [else #f]))) \ No newline at end of file + (any/c any/c . -> . coerce/boolean?) + (cond + [(list? container) (member item container)] ; returns #f or sublist beginning with item + [(vector? container) (vector-member item container)] ; returns #f or zero-based item index + [(hash? container) + (and (hash-has-key? container item) (get container item))] ; returns #f or hash value + [(string? container) (regexp-match (->string item) (->string container))] ; returns #f or substring beginning with item + [(symbol? container) ((->string item) . in? . (->string container))] ; returns #f or subsymbol (?!) beginning with item + [else #f])) \ No newline at end of file diff --git a/define.rkt b/define.rkt index 981526a..8c424ee 100644 --- a/define.rkt +++ b/define.rkt @@ -4,6 +4,9 @@ (provide define+provide define+provide/contract define/contract+provide) +;; each define macro recursively converts any form of define +;; into its lambda form (define name body ...) and then operates on that. + (define-syntax (define+provide stx) (syntax-case stx () [(_ (proc arg ... . rest-arg) body ...) @@ -14,6 +17,7 @@ (provide name) (define name body ...))])) + (define-syntax (define+provide/contract stx) (syntax-case stx () [(_ (proc arg ... . rest-arg) contract body ...) @@ -25,7 +29,6 @@ (define name body ...))])) - (define-syntax (define/contract+provide stx) (syntax-case stx () [(_ (proc arg ... . rest-arg) contract body ...)