on 140ac0e help sign in
504 lines 5.4 kB history raw
1# 1a: basic arithmetic
2### `++add`
4Add
6Produces the sum of `a` and `b`.
8Accepts
9-------
11`a` is an atom.
13`b` is an atom.
15Produces
16--------
18An atom.
20Source
21------
23 ++ add :: add
24 ~/ %add
25 |= [a/@ b/@]
26 ^- @
27 ?: =(0 a) b
28 $(a (dec a), b +(b))
30Examples
31--------
33 > (add 2 2)
34 4
35 > (add 1 1.000.000)
36 1.000.001
37 > (add 1.333 (mul 2 2))
38 1.337
40***
41### `++dec`
43Decrement
45Decrements `a` by `1`.
47Accepts
48-------
50`a` is an atom.
52Produces
53--------
55An atom.
57Source
58------
60 ++ dec :: decrement
61 ~/ %dec
62 |= a/@
63 ~| %decrement-underflow
64 ?< =(0 a)
65 =+ b=0
66 |- ^- @
67 ?: =(a +(b)) b
68 $(b +(b))
70Examples
71--------
73 > (dec 7)
74 6
75 > (dec 0)
76 ! decrement-underflow
77 ! exit
81***
82### `++div`
84Divide
86Computes `a` divided by `b`.
88Accepts
89-------
91`a` is an atom.
93`b` is an atom.
95Produces
96--------
98An atom.
100Source
101------
103 ++ div :: divide
104 ~/ %div
105 |= [a/@ b/@]
106 ^- @
107 ~| 'div'
108 ?< =(0 b)
109 =+ c=0
110 |-
111 ?: (lth a b) c
112 $(a (sub a b), c +(c))
113 ::
115Examples
116--------
118 > (div 4 2)
119 2
120 > (div 17 8)
121 2
122 > (div 20 30)
123 0
126***
127### `++gte`
129Greater-than/equal
131Tests whether `a` is greater than a number `b`.
133Accepts
134-------
136`a` is an atom.
138`b` is an atom.
140Produces
141--------
143A boolean.
145Source
146------
148 ++ gte :: greater-equal
149 ~/ %gte
150 |= {a/@ b/@}
151 ^- ?
152 !(lth a b)
155Examples
156--------
158 > (gte 100 10)
159 %.y
160 > (gte 4 4)
161 %.y
162 > (gte 3 4)
163 %.n
167***
168### `++gth`
170Greater-than
172Tests whether `a` is greater than `b`.
174Accepts
175-------
177`a` is an atom.
179`b` is an atom.
181Produces
182--------
184A boolean.
186Source
187------
189 ++ gth :: greater-than
190 ~/ %gth
191 |= {a/@ b/@}
192 ^- ?
193 !(lte a b)
197Examples
198--------
200 > (gth 'd' 'c')
201 %.y
202 > (gth ~h1 ~m61)
203 %.n
207***
208### `++lte`
210Less-than/equal
212Tests whether `a` is less than or equal to `b`.
214Accepts
215-------
217`a` is an atom.
219`b` is an atom.
221Produces
222--------
224A boolean.
226Source
227------
229 ++ lte :: less-equal
230 ~/ %lte
231 |= {a/@ b/@}
232 |(=(a b) (lth a b))
234 ::
236Examples
237--------
239 > (lte 4 5)
240 %.y
241 > (lte 5 4)
242 %.n
243 > (lte 5 5)
244 %.y
245 > (lte 0 0)
246 %.y
250***
251### `++lth`
253Less-than
255Tests whether `a` is less than `b`.
257Accepts
258-------
260`a` is an atom.
262`b` is an atom.
264Produces
265--------
267A boolean.
269Source
270------
272 ++ lth :: less-than
273 ~/ %lth
274 |= {a/@ b/@}
275 ^- ?
276 ?& !=(a b)
277 |-
278 ?| =(0 a)
279 ?& !=(0 b)
280 $(a (dec a), b (dec b))
281 == == ==
283Examples
284--------
286 > (lth 4 5)
287 %.y
288 > (lth 5 4)
289 %.n
290 > (lth 5 5)
291 %.n
292 > (lth 5 0)
293 %.n
296***
297### `++max`
299Maximum
301Computes the greater of `a` and `b`.
303Accepts
304-------
306`a` is an atom.
308`b` is an atom.
310Produces
311--------
313An atom.
315Source
316------
318 ++ max :: maximum
319 ~/ %max
320 |= {a/@ b/@}
321 ^- @
322 ?: (gth a b) a
323 b
325Examples
326--------
328 > (max 10 100)
329 100
330 > (max 10.443 9)
331 10.443
332 > (max 0 1)
333 1
337***
338### `++min`
340Minimum
342Computes the lesser of `a` and `b`.
344Accepts
345-------
347`a` is an atom.
349`b` is an atom.
351Produces
352--------
354An atom.
356Source
357------
359 ++ min :: minimum
360 ~/ %min
361 |= {a/@ b/@}
362 ^- @
363 ?: (lth a b) a
364 b
366Examples
367--------
369 > (min 10 100)
370 10
371 > (min 10.443 9)
372 9
373 > (min 0 1)
374 0
378***
379### `++mod`
381Modulus
383Computes the remainder of dividing `a` by `b`.
385Accepts
386-------
388`a` is an atom.
390`b` is an atom.
392Produces
393--------
395An atom.
397Source
398------
400 ++ mod :: remainder
401 ~/ %mod
402 |: [a=`@`1 b=`@`1]
403 ^- @
404 ?< =(0 b)
405 (sub a (mul b (div a b)))
408Examples
409--------
411 > (mod 5 2)
412 1
413 > (mod 5 5)
414 0
418***
419### `++mul`
421Multiply
423Multiplies `a` by `b`.
425Accepts
426-------
428`a` is an atom.
430`b` is an atom.
432Produces
433--------
435An atom.
437Source
438------
440 ++ mul :: multiply
441 ~/ %mul
442 |: [a=`@`1 b=`@`1]
443 ^- @
444 =+ c=0
445 |-
446 ?: =(0 a) c
447 $(a (dec a), c (add b c))
449Examples
450--------
452 > (mul 3 4)
453 12
454 > (mul 0 1)
455 0
459***
460### `++sub`
462Subtract
464Subtracts `b` from `a`.
466Accepts
467-------
469`a` is an atom.
471`b` is an atom.
473Produces
474--------
476An atom.
478Source
479------
481 ++ sub :: subtract
482 ~/ %sub
483 |= [a/@ b/@]
484 ~| %subtract-underflow
485 ^- @
486 ?: =(0 b) a
487 $(a (dec a), b (dec b))
489Examples
490--------
492 > (sub 10 5)
493 5
494 > (sub 243 44)
495 199
496 > (sub 5 0)
497 5
498 > (sub 0 5)
499 ! subtract-underflow
500 ! exit
504***