3 ms·
In Racket and other Schemes parens and square brackets are interchangeable. The Racket style guide suggests to use square brackets in let- or cond-like expressi
by steinuil 9y ago
In Racket and other Schemes parens and square brackets are interchangeable. The Racket style guide suggests to use square brackets in let- or cond-like expression, or generally any expression with a list of lists of fixed length that are not supposed to be evaluated. The expression you posted would become like this:
(do ([i 1 (+ i 1)])
((> i 100))
(display
(cond [(= 0 (modulo i 15)) "FizzBuzz"]
[(= 0 (modulo i 3)) "Fizz"]
[(= 0 (modulo i 5)) "Buzz"]
[else i]))
(newline))
I personally think this helps a lot with the problem of parsing s-expressions visually.
- soegaard 9y agoAlso: It is rare to use `do`. #lang racket (require math) (for ([i 100]) (displayln (cond [(divides? 15 i) "FizzBuzz"] [(divides? 3 i) "Fizz"] [(divides? 5 i) "Buzz"] [else i])))