aboutsummaryrefslogtreecommitdiff
path: root/module/text
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2020-06-13 00:16:10 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2020-06-13 00:16:10 +0200
commit78b1b9f75b4e8289aeef804b46eb816b9884159b (patch)
treea7c22c92f0421ff87c0fc9c72037659664c899cb /module/text
parentResolve some TODO's. (diff)
downloadcalp-78b1b9f75b4e8289aeef804b46eb816b9884159b.tar.gz
calp-78b1b9f75b4e8289aeef804b46eb816b9884159b.tar.xz
Add 'a-form' to my ordinals.
Diffstat (limited to 'module/text')
-rw-r--r--module/text/numbers.scm18
1 files changed, 12 insertions, 6 deletions
diff --git a/module/text/numbers.scm b/module/text/numbers.scm
index c590c188..4c76a028 100644
--- a/module/text/numbers.scm
+++ b/module/text/numbers.scm
@@ -88,13 +88,15 @@
(string-append "det stora talet "
(number->string n))]))
-(define-public (number->string-ordinal n)
+(define*-public (number->string-ordinal
+ n key: a-form?)
+ (define a-string (if a-form? "a" "e"))
(cond [(>= -3 n) (format #f "~a sista" (number->string-ordinal (- n)))]
[(= -2 n) "näst sista"]
[(= -1 n) "sista"]
[(= 0 n) "nollte"] ;
- [(= 1 n) "förste"]
- [(= 2 n) "andre"]
+ [(= 1 n) (format #f "först~a" a-string)]
+ [(= 2 n) (format #f "andr~a" a-string)]
[(= 3 n) "tredje"]
[(= 4 n) "fjärde"]
[(= 5 n) "femte"]
@@ -115,7 +117,9 @@
[(<= 20 n 29) (format #f "tjugo~a"
(if (= 20 n)
"nde"
- (number->string-ordinal (- n 20))))]
+ (number->string-ordinal
+ (- n 20)
+ a-form?: a-form?)))]
[(<= 30 n 99)
(let* ((big small (floor/ n 10)))
(format #f "~atio~a"
@@ -125,7 +129,8 @@
[else (number->string-cardinal big)])
(if (zero? (modulo small 10))
"nde"
- (number->string-ordinal small))))]
+ (number->string-ordinal
+ small a-form?: a-form?))))]
[(= n 100) "hundrade"]
[(= n 1000) "tusende"]
[else
@@ -133,7 +138,8 @@
(string-append (number->string-cardinal (* big 100))
(if (zero? small)
"de"
- (number->string-ordinal small))))]))
+ (number->string-ordinal
+ small a-form?: a-form?))))]))
;; (each-string 1) ; => "varje"
;; (each-string 2) ; => "varannan"