File: contract.rkt

package info (click to toggle)
racket 7.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 125,432 kB
  • sloc: ansic: 258,980; pascal: 59,975; sh: 33,650; asm: 13,558; lisp: 7,124; makefile: 3,329; cpp: 2,889; exp: 499; python: 274; xml: 11
file content (112 lines) | stat: -rw-r--r-- 4,120 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#lang racket/base

(require racket/contract
         racket/draw
         racket/class)

(provide
 (except-out
  (all-defined-out)
  maybe-function/c
  maybe-apply
  plot-colors/c
  pen-widths/c
  plot-pen-styles/c
  plot-brush-styles/c
  alphas/c
  labels/c)
 (contract-out
  [maybe-function/c  (-> contract? contract? contract?)]
  [maybe-apply       (-> (maybe-function/c any/c any/c) any/c any/c)]
  [plot-colors/c        (-> contract? contract?)]
  [pen-widths/c         (-> contract? contract?)]
  [plot-pen-styles/c    (-> contract? contract?)]
  [plot-brush-styles/c  (-> contract? contract?)]
  [alphas/c             (-> contract? contract?)]
  [labels/c             (-> contract? contract?)])
 (rename-out [natural-number/c nat/c])
 font-family/c
 treeof)

;; ===================================================================================================
;; Plot-specific contracts

(define anchor/c (one-of/c 'top-left    'top    'top-right
                           'left        'center 'right
                           'bottom-left 'bottom 'bottom-right))

(define color/c (or/c (list/c real? real? real?)
                      string? symbol?
                      (is-a?/c color%)))

(define plot-color/c (or/c exact-integer? color/c))

(define plot-pen-style/c (or/c exact-integer?
                               (one-of/c 'transparent 'solid    'dot 'long-dash
                                         'short-dash  'dot-dash)))

(define plot-brush-style/c (or/c exact-integer?
                                 (one-of/c 'transparent      'solid
                                           'bdiagonal-hatch  'fdiagonal-hatch 'crossdiag-hatch
                                           'horizontal-hatch 'vertical-hatch  'cross-hatch)))

(module typed-defs typed/racket/base
  (require "type-doc.rkt")
  
  (provide (all-defined-out))
  
  (defthing known-point-symbols (Listof Symbol) #:document-value
    (list 'dot               'point            'pixel
          'plus              'times            'asterisk
          '5asterisk         'odot             'oplus
          'otimes            'oasterisk        'o5asterisk
          'circle            'square           'diamond
          'triangle          'fullcircle       'fullsquare
          'fulldiamond       'fulltriangle     'triangleup
          'triangledown      'triangleleft     'triangleright
          'fulltriangleup    'fulltriangledown 'fulltriangleleft
          'fulltriangleright 'rightarrow       'leftarrow
          'uparrow           'downarrow        '4star
          '5star             '6star            '7star
          '8star             'full4star        'full5star
          'full6star         'full7star        'full8star
          'circle1           'circle2          'circle3
          'circle4           'circle5          'circle6
          'circle7           'circle8          'bullet
          'fullcircle1       'fullcircle2      'fullcircle3
          'fullcircle4       'fullcircle5      'fullcircle6
          'fullcircle7       'fullcircle8)))

(require (submod "." typed-defs))
(provide (all-from-out 'typed-defs))

(define point-sym/c (or/c char? string? integer? (apply one-of/c known-point-symbols)))

(define (maybe-function/c in-contract out-contract)
  (or/c out-contract (in-contract . -> . out-contract)))

(define (maybe-apply f arg)
  (cond [(procedure? f)  (f arg)]
        [else            f]))

(define (plot-colors/c in-contract)
  (maybe-function/c in-contract (listof plot-color/c)))

(define (pen-widths/c in-contract)
  (maybe-function/c in-contract (listof (>=/c 0))))

(define (plot-pen-styles/c in-contract)
  (maybe-function/c in-contract (listof plot-pen-style/c)))

(define (plot-brush-styles/c in-contract)
  (maybe-function/c in-contract (listof plot-brush-style/c)))

(define (alphas/c in-contract)
  (maybe-function/c in-contract (listof (real-in 0 1))))

(define (labels/c in-contract)
  (maybe-function/c in-contract (listof (or/c string? #f))))

(define (treeof elem-contract)
  (or/c elem-contract
        (listof (recursive-contract (treeof elem-contract) #:flat))))