about summary refs log tree commit diff stats
path: root/janet/giblang.janet
blob: f8b9d4e292c3faa305d4255f1093f166839226d2 (plain) (blame)
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
# https://pbat.ch/wiki/giblang/

(def cons (array
           "b" "c" "d" "f"
           "g" "h" "j" "k"
           "l" "m" "n" "p"
           "r" "s" "t" "v"
           "w" "z" "ch" "sh"
           "zh" "th"))

(def vow (array "a" "e" "i" "o" "u" "y" "ee" "ai" "ae"))

(defn rpick (t)
  (t (math/floor (* (math/random) (length t)))))

(defn seed () (math/seedrandom (os/time)))

(defn syl () (string (rpick cons) (rpick vow)))

(defn word ()
  (do
    (var str "")
    (for i 0 (+ (math/floor (* (math/random) 3)) 1)
      (set str (string str (syl))))
    (cond (> (math/random) 0.2)
          (set str (string str (rpick cons))))
    (string str)))

(defn speak [number-of-words]
  (seed)
  (var words "")
  (var i 0)
  (while (< i number-of-words)
      (set words (string words (word) " "))
      (++ i))
  (print words))

(speak 7)