~jojo/Carth

ref: 65fedc5ad30893bac36f128dac201ff7081f8e1b Carth/examples/fizzbuzz.carth -rw-r--r-- 458 bytes
65fedc5aJoJo Allow Box in pattern to dereference 1 year, 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(import std)

(define (start _) (fizzbuzz unit))

(define (fizzbuzz _)
  (for (range 1 100)
       (comp 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
  (fun-match
    (case 1 "one")
    (case 2 "two")
    (case n (show-int n))))