Skip to content

Instantly share code, notes, and snippets.

@yurrriq
Last active February 18, 2016 11:37
Show Gist options
  • Save yurrriq/58dc75be826ebaebee53 to your computer and use it in GitHub Desktop.
Save yurrriq/58dc75be826ebaebee53 to your computer and use it in GitHub Desktop.
FizzBuzz in LFE
(defmodule fizzbuzz
(export (fizzbuzz 1)))
(defun fizzbuzz (n)
(lists:foreach
(lambda (x) (lfe_io:format "~p~n" `(,x)))
(lists:map #'fizz/1 (lists:seq 1 n))))
(defun fizz (n) (fizz n (rem n 3) (rem n 5)))
(defun fizz
([_ 0 0] 'FizzBuzz)
([_ 0 _] 'Fizz)
([_ _ 0] 'Buzz)
([n _ _] n))
@yurrriq
Copy link
Author

yurrriq commented Aug 16, 2015

It might be cool to define prn:

(defun prn (x) (io:format '"~p~n" `(,x)))

and refer to it in the foreach/2 form:

(lists:foreach #'prn/1 ...)

@yurrriq
Copy link
Author

yurrriq commented Aug 17, 2015

Strings are self quoting so there is no need to quote them.

@yurrriq
Copy link
Author

yurrriq commented Aug 17, 2015

> (fizzbuzz 15)
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment