~jojo/Carth

ref: b144030d9a5428cf4472e3c55258d8983c20982d Carth/examples/fizzbuzz.carth -rw-r--r-- 448 bytes
b144030dJoJo Make main IO Unit, i.e. (Fun RealWorld [Unit RealWorld]) 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(import std)

(define (main real-world) (fizzbuzz real-world))

(define fizzbuzz
  (io/for (range 1 100)
          (<o display fizzbuzz')))

(define (fizzbuzz' n)
  (match [(divisible? n 3) (divisible? n 5)]
    (case [False False] (my-show-int n))
    (case [True  False] "Fizz")
    (case [False True ] "Buzz")
    (case [True  True ] "Fizzbuzz")))

(define my-show-int
  (fmatch
    (case 1 "one")
    (case 2 "two")
    (case n (show-int n))))