Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
FizzBuzz in Hy
#! bin/hy
; -*- mode: lisp; mode: paredit -*-
(import fizzbuzz-macros)
(defn fizzbuzz [n]
(let [[result ""]]
(if (zero? (% n 3))
(setv result (+ result "fizz")))
(if (zero? (% n 5))
(setv result (+ result "buzz")))
(if (and (not (zero? (% n 3))) (not (zero? (% n 5))))
(setv result (str n)))
result))
(print (map fizzbuzz (range 1 16)))
from hy.macros import macro
from hy.models.expression import HyExpression
from hy.models.symbol import HySymbol
from hy.models.integer import HyInteger
@macro("zero?")
def zerop(tree):
tree.pop(0)
expr = tree.pop(0)
return HyExpression([HySymbol('='),
expr,
HyInteger(0)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment