diff --git a/collects/unstable/bytes.rkt b/collects/unstable/bytes.rkt index f8e096ecee..c871642225 100644 --- a/collects/unstable/bytes.rkt +++ b/collects/unstable/bytes.rkt @@ -21,6 +21,8 @@ ;; "read with bytes". Regardless, I see little point in composing two ;; functions where the two names are clear enough -- you might consider ;; looking at the version in CL. +;; Ryan: I agree. More useful would be a version that checked that the +;; bytes contains only one S-expr and errors otherwise. (define (write/bytes v) (define by (open-output-bytes)) diff --git a/collects/unstable/contract.rkt b/collects/unstable/contract.rkt index 91cdf8c04c..10194ab1ed 100644 --- a/collects/unstable/contract.rkt +++ b/collects/unstable/contract.rkt @@ -9,13 +9,6 @@ (define port-number? (between/c 1 65535)) (define tcp-listen-port? (between/c 0 65535)) -(define non-empty-string/c - (and/c string? - (lambda (s) (not (zero? (string-length s)))))) -;; Eli: If this gets in, there should also be versions for bytes, lists, and -;; vectors. -;; Ryan: How about just making these predicates? Predicates are more broadly applicable, -;; and when used as a contract we get the descriptive name for free. (define (non-empty-string? x) (and (string? x) (not (zero? (string-length x))))) (define (non-empty-bytes? x) diff --git a/collects/unstable/dict.rkt b/collects/unstable/dict.rkt index 6d99b492e5..6cef0db5f0 100644 --- a/collects/unstable/dict.rkt +++ b/collects/unstable/dict.rkt @@ -9,10 +9,11 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (dict-empty? dict) - (= (dict-count dict) 0)) + (not (dict-iterate-first dict))) ;; Eli: This encourages ignoring the actual representation, and the fact ;; that `dict-count' can in some cases be an O(N) operation. (And to ;; make things worse, it's not even mentioned in the docs.) +;; Ryan: Fixed complexity. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; @@ -135,6 +136,10 @@ ;; union of two alists, etc. Alternatively, just write a function for ;; merging two hash tables (and call it `hash-union', of course). +;; Ryan: I prefer the names dict-add-all and dict-add-all!---no connotations +;; of symmetry, and it makes it clear that the first argument determines the +;; representation (and key constraints, etc). + (define (dict-union #:combine [combine #f] #:combine/key [combine/key diff --git a/collects/unstable/pretty.rkt b/collects/unstable/pretty.rkt index 5a544428ff..b9fb48a668 100644 --- a/collects/unstable/pretty.rkt +++ b/collects/unstable/pretty.rkt @@ -14,3 +14,7 @@ (define pretty-format/write (pretty-format/pretty pretty-write)) (define pretty-format/display (pretty-format/pretty pretty-display)) (define pretty-format/print (pretty-format/pretty pretty-print)) + +;; Ryan: There doesn't seem to be any 'format' going on. Perhaps call +;; them pretty-write-to-string, etc? +;; Bleh, just saw pretty-format in racket/pretty :( diff --git a/collects/unstable/scribblings/contract.scrbl b/collects/unstable/scribblings/contract.scrbl index 41fa0362a5..a033360731 100644 --- a/collects/unstable/scribblings/contract.scrbl +++ b/collects/unstable/scribblings/contract.scrbl @@ -7,8 +7,21 @@ @unstable-header[] -@defthing[non-empty-string/c contract?]{ -Contract for non-empty strings. +@deftogether[[ +@defproc[(non-empty-string? [x any/c]) boolean?] +@defproc[(non-empty-list? [x any/c]) boolean?] +@defproc[(non-empty-bytes? [x any/c]) boolean?] +@defproc[(non-empty-vector? [x any/c]) boolean?]]]{ + +Returns @racket[#t] if @racket[x] is of the appropriate data type +(string, list, bytes, or vector, respectively) and is not empty; +returns @racket[#f] otherwise. +} + +@defproc[(singleton-list? [x any/c]) boolean?]{ + +Returns @racket[#t] if @racket[x] is a list of one element; returns +@racket[#f] otherwise. } @defthing[port-number? contract?]{ diff --git a/collects/web-server/http/redirect.rkt b/collects/web-server/http/redirect.rkt index e1136463c4..4fa6a0744a 100644 --- a/collects/web-server/http/redirect.rkt +++ b/collects/web-server/http/redirect.rkt @@ -25,7 +25,7 @@ (provide/contract [redirect-to - (->* (non-empty-string/c) (redirection-status? #:headers (listof header?)) + (->* (non-empty-string?) (redirection-status? #:headers (listof header?)) response/full?)] [redirection-status? (any/c . -> . boolean?)] [permanently redirection-status?]