diff --git a/collects/plot/common/contract.rkt b/collects/plot/common/contract.rkt index 425f521781..8d81a9f075 100644 --- a/collects/plot/common/contract.rkt +++ b/collects/plot/common/contract.rkt @@ -4,27 +4,16 @@ unstable/latent-contract/defthing) (provide (except-out (all-defined-out) - treeof maybe-function/c maybe-apply plot-colors/c pen-widths/c plot-pen-styles/c plot-brush-styles/c alphas/c labels/c) (activate-contract-out - treeof maybe-function/c maybe-apply plot-colors/c pen-widths/c plot-pen-styles/c plot-brush-styles/c alphas/c labels/c) (rename-out [natural-number/c nat/c]) truth/c) -;; =================================================================================================== -;; Convenience - -(defcontract contract/c (or/c contract? (any/c . -> . any/c))) - -(defcontract (treeof [elem-contract contract/c]) - (or/c elem-contract - (listof (recursive-contract (treeof elem-contract))))) - ;; =================================================================================================== ;; Plot-specific contracts diff --git a/collects/plot/contracted/plot-element.rkt b/collects/plot/contracted/plot-element.rkt index e5de3c0ebb..a2e9dfacd1 100644 --- a/collects/plot/contracted/plot-element.rkt +++ b/collects/plot/contracted/plot-element.rkt @@ -1,6 +1,6 @@ #lang racket/base -(require racket/contract unstable/latent-contract racket/class) +(require racket/contract unstable/latent-contract unstable/contract racket/class) (require "../common/contract.rkt" "../common/plot-element.rkt" diff --git a/collects/plot/plot2d/plot.rkt b/collects/plot/plot2d/plot.rkt index 3fd85f4e73..f018aaa64a 100644 --- a/collects/plot/plot2d/plot.rkt +++ b/collects/plot/plot2d/plot.rkt @@ -3,6 +3,7 @@ ;; Procedures that plot 2D renderers. (require racket/draw racket/snip racket/contract racket/list racket/class racket/match + unstable/contract slideshow/pict unstable/parameter-group unstable/lazy-require diff --git a/collects/plot/plot3d/plot.rkt b/collects/plot/plot3d/plot.rkt index 3f8e2baa4a..9453c925a3 100644 --- a/collects/plot/plot3d/plot.rkt +++ b/collects/plot/plot3d/plot.rkt @@ -3,6 +3,7 @@ ;; Procedures that plot 3D renderers. (require racket/draw racket/snip racket/match racket/list racket/class racket/contract + unstable/contract slideshow/pict unstable/parameter-group unstable/lazy-require diff --git a/collects/plot/scribblings/common.rkt b/collects/plot/scribblings/common.rkt index 5ba0576f2c..7aea29a5b9 100644 --- a/collects/plot/scribblings/common.rkt +++ b/collects/plot/scribblings/common.rkt @@ -6,7 +6,8 @@ slideshow/pict db plot - plot/utils) + plot/utils + unstable/contract) plot plot/utils plot/doc @@ -19,7 +20,8 @@ slideshow/pict db plot - plot/utils)) + plot/utils + unstable/contract)) (all-from-out plot) (all-from-out plot/doc) (all-from-out plot/utils) diff --git a/collects/plot/scribblings/contracts.scrbl b/collects/plot/scribblings/contracts.scrbl index d352ab6760..72d7aa573d 100644 --- a/collects/plot/scribblings/contracts.scrbl +++ b/collects/plot/scribblings/contracts.scrbl @@ -137,14 +137,3 @@ Like @(racket plot-colors/c), but for opacities. Like @racket[plot-colors/c], but for strings. This is used, for example, to label @racket[stacked-histogram]s. } - -@section{Convenience Contracts} - -@doc-apply[contract/c]{ -Identifies @racket[contract?]s and predicates that can be used as contracts. -} - -@doc-apply[treeof]{ -Identifies trees of values that meet the contract @(racket ct). -Used by @(racket plot) and @(racket plot3d) to construct the contract for a tree of @(racket renderer2d?) or @(racket renderer3d?). -} diff --git a/collects/plot/scribblings/utils.scrbl b/collects/plot/scribblings/utils.scrbl index 5305ffd8da..c9bd25e349 100644 --- a/collects/plot/scribblings/utils.scrbl +++ b/collects/plot/scribblings/utils.scrbl @@ -268,19 +268,23 @@ Returns @racket[#t] if @racket[x] is @racket[+nan.0]. } @doc-apply[ceiling-log/base]{ -Like @racket[(ceiling (/ (log x) (log b)))], but @racket[ceiling-log/base] is not susceptible to floating-point error when given an exact @racket[x]. +Like @racket[(ceiling (/ (log x) (log b)))], but @racket[ceiling-log/base] is not susceptible to floating-point error. @examples[#:eval plot-eval + (ceiling (/ (log 100) (log 10))) + (ceiling-log/base 10 100) (ceiling (/ (log 1/1000) (log 10))) (ceiling-log/base 10 1/1000)] Various number-formatting functions use this. } @doc-apply[floor-log/base]{ -Like @racket[(floor (/ (log x) (log b)))], but @racket[floor-log/base] is not susceptible to floating-point error when given an exact @racket[x]. +Like @racket[(floor (/ (log x) (log b)))], but @racket[floor-log/base] is not susceptible to floating-point error. @examples[#:eval plot-eval + (floor (/ (log 100) (log 10))) + (floor-log/base 10 100) (floor (/ (log 1000) (log 10))) (floor-log/base 10 1000)] -Various number-formatting functions use this. +This is a generalization of @racket[order-of-magnitude]. } @doc-apply[maybe-inexact->exact]{ @@ -506,10 +510,6 @@ See @racket[date-ticks] for more information. To plot a time series using dates pulled from an SQL database, simply set the relevant axis ticks (probably @racket[plot-x-ticks]) to @racket[date-ticks], and convert the dates to seconds using @racket[datetime->real] before passing them to @racket[lines]. To keep time zone offsets from influencing the plot, set them to @racket[0] first. - -Does @racket[sql-time?] work? - -@racketmodname[db/base] } @defstruct[plot-time ([second (and/c (>=/c 0) ( . any/c))) + +(define (treeof elem-contract) + (or/c elem-contract + (listof (recursive-contract (treeof elem-contract) #:flat)))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Exports @@ -192,4 +200,9 @@ [truth/c flat-contract?] [sequence/c (->* [] [] #:rest (listof contract?) contract?)] + + [contract/c contract?] + + [treeof (contract/c . -> . contract?)] ) + diff --git a/collects/unstable/scribblings/contract.scrbl b/collects/unstable/scribblings/contract.scrbl index 9cc84cb9dd..ae67cbba32 100644 --- a/collects/unstable/scribblings/contract.scrbl +++ b/collects/unstable/scribblings/contract.scrbl @@ -116,4 +116,22 @@ for instance, a wrapped list is not guaranteed to satisfy @racket[list?]. } +@addition{@author+email["Neil Toronto" "neil.toronto@gmail.com"]} + +@defthing[contract/c contract?]{ +Identifies contracts and predicates that can be used as contracts. +} + +@defproc[(treeof [elem-contract contract/c]) contract?]{ +Identifies values that meet the contract @racket[elem-contract], lists of such values, lists of lists, and so on. +@examples[#:eval the-eval + (define number-tree/c (treeof number?)) + (flat-contract? number-tree/c) + (define number-tree? (flat-contract-predicate number-tree/c)) + (number-tree? 4) + (number-tree? '(4 5)) + (number-tree? '((4 5) 6)) + (number-tree? '(4 . 5))] +} + @(close-eval the-eval)