~jojo/Carth

ref: ee5251b9b8bf725c1d5499fedf9c9671308fa476 Carth/examples/fizzbuzz.carth -rw-r--r-- 455 bytes
ee5251b9JoJo Glob exports in AST modules -- minor refactor / cleanup 2 years 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 Unit) (fizzbuzz Unit))

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

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

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