DEV Community

Discussion on: Fizz Buzz in Every Language

avalander profile image
Avalander • Edited

Here's my implementation in Racket

(define (mult-15? n)
  (and (mult-5? n)
       (mult-3? 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"]
    [else n]))

(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.

gypsydave5 profile image
David Wickes

Ah come on @avalander - surely you should've written a FizzBuzz DSL in Racket? 😉

avalander profile image

I should, but I don't know enough Racket for that yet 😅

renegadecoder94 profile image
Jeremy Grifski

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.

avalander profile image

Thanks! I've just started learning it myself. I can recommend the book Realm of Racket if you want to give it a shot.