Moved contract/c and treeof to unstable/contracts

Little plot doc fixes
This commit is contained in:
Neil Toronto 2012-01-27 18:15:03 -07:00
parent ec96e37e09
commit 7d28eef00d
9 changed files with 45 additions and 32 deletions

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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?).
}

View File

@ -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) (</c 60))]

View File

@ -171,6 +171,14 @@
(lambda (idx . elems) #t)))))))
sequence?)))
;; Added by ntoronto
(define contract/c (or/c contract? (any/c . -> . 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?)]
)

View File

@ -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)