Here's my implementation in Racket
(define (mult-15? n)
(and (mult-5? n)
(define (mult-5? n)
(= (modulo n 5) 0))
(define (mult-3? n)
(= (modulo n 3) 0))
(define (fizzbuzz n)
[(mult-15? n) "FizzBuzz"]
[(mult-5? n) "Buzz"]
[(mult-3? n) "Fizz"]
(define (print-list xs)
(map displayln xs))
(print-list (map fizzbuzz (range 1 101)))
The print-list function is a bit redundant, since (map fizzbuzz (range 1 101)) will already print the resulting list to the console.
(map fizzbuzz (range 1 101))
Great stuff! I like racket a lot, but I haven't written any code in it myself. The fact that there are so many dialects of it is pretty cool to me.
Thanks! I've just started learning it myself. I can recommend the book Realm of Racket if you want to give it a shot.
Ah come on @avalander
- surely you should've written a FizzBuzz DSL in Racket? 😉
I should, but I don't know enough Racket for that yet 😅
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.