aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/documentation/lux/type/unit.lux
blob: a3d37d5524b08448814537f49a5d53412b86a676 (plain)
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
(.using
 [library
  [lux {"-" and}
   ["$" documentation {"+" documentation:}]
   [control
    ["<>" parser
     ["<[0]>" code]]]
   [data
    ["[0]" text {"+" \n}
     ["%" format {"+" format}]]]
   [macro
    ["[0]" template]]
   [math
    [number
     ["[0]" ratio]]]]]
 [\\library
  ["[0]" /]])

(documentation: (/.Qty unit)
  "A quantity with an associated unit of measurement.")

(documentation: (/.Unit unit)
  "A unit of measurement, to qualify numbers with.")

(documentation: (/.Scale scale)
  "A scale of magnitude.")

(documentation: /.Pure
  "A pure, unit-less quantity.")

(documentation: /.unit:
  (format "Define a unit of measurement."
          \n "Both the name of the type, and the name of the Unit implementation must be specified.")
  [(unit: .public Feet feet)])

(documentation: /.scale:
  "Define a scale of magnitude."
  [(scale: .public Bajillion bajillion
     [1 1,234,567,890])])

(documentation: /.re_scaled
  ""
  [(re_scaled from to quantity)])

(template [<type> <scale>]
  [(`` (documentation: <scale>
         (let [numerator (the [/.ratio ratio.#numerator] <scale>)
               denominator (the [/.ratio ratio.#denominator] <scale>)]
           (format "The '" (~~ (template.text [<scale>])) "' scale, from " (%.nat numerator) " to " (%.nat denominator) "."))))]

  [/.Kilo /.kilo]
  [/.Mega /.mega]
  [/.Giga /.giga]

  [/.Milli /.milli]
  [/.Micro /.micro]
  [/.Nano /.nano]
  )

(template [<unit>]
  [(`` (documentation: <unit>
         (format "The '" (~~ (template.text [<unit>])) "' unit of meaurement.")))]

  [/.gram]
  [/.meter]
  [/.litre]
  [/.second]
  )

(.def: .public documentation
  (.List $.Module)
  ($.module /._
            ""
            [..Qty
             ..Unit
             ..Scale
             ..Pure
             ..unit:
             ..scale:
             ..re_scaled
             ..kilo
             ..mega
             ..giga
             ..milli
             ..micro
             ..nano
             ..gram
             ..meter
             ..litre
             ..second
             ($.default /.Gram)
             ($.default /.Meter)
             ($.default /.Litre)
             ($.default /.Second)
             ($.default /.pure)
             ($.default /.number)
             ($.default /.equivalence)
             ($.default /.order)
             ($.default /.enum)
             ($.default /.Kilo)
             ($.default /.Mega)
             ($.default /.Giga)
             ($.default /.Milli)
             ($.default /.Micro)
             ($.default /.Nano)
             ($.default /.+)
             ($.default /.-)
             ($.default /.*)
             ($.default /./)]
            []))