/
english.scm
73 lines (62 loc) · 1.33 KB
/
english.scm
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
;;; Copyright 2016-2017 by Christian Jaeger <ch@christianjaeger.ch>
;;; This file is free software; you can redistribute it and/or modify
;;; it under the terms of the GNU General Public License (GPL) as published
;;; by the Free Software Foundation, either version 2 of the License, or
;;; (at your option) any later version.
(require easy
test)
(export english:numerize
english:the-natural
english:weekdays)
(include "cj-standarddeclares.scm")
(def (english:numerize singular-str #(natural0? n))
(if (= n 1) singular-str
(string-append singular-str "s")))
(def (english:the-natural #(natural0? n))
(let* ((s (.string n))
(len (.length s))
(c (string-ref s (dec len))))
(string-append s
(if (< 10 n 20)
"th"
(case c
((#\1) "st")
((#\2) "nd")
((#\3) "rd")
(else
"th"))))))
(TEST
> (map english:the-natural (iota 25))
("0th"
"1st"
"2nd"
"3rd"
"4th"
"5th"
"6th"
"7th"
"8th"
"9th"
"10th"
"11th"
"12th"
"13th"
"14th"
"15th"
"16th"
"17th"
"18th"
"19th"
"20th"
"21st"
"22nd"
"23rd"
"24th")
> (english:the-natural 31)
"31st"
> (english:the-natural 101)
"101st"
> (english:the-natural 203)
"203rd")
(def english:weekdays
'#("Sunday" "Monday" "Tuesday" "Wednesday" "Thursday" "Friday" "Saturday"))