Created
April 28, 2015 21:52
-
-
Save pmarreck/276a00f4a30ddf5dd5e6 to your computer and use it in GitHub Desktop.
elixir dynamic method definitions?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ thousand: 2, million: 3, billion: 4, trillion: 5, quadrillion: 6, quintillion: 7, sextillion: 8, septillion: 9, octillion: 10, nonillion: 11, decillion: 12 ] | |
|> Enum.each(fn {illion, factor} -> | |
IO.puts "illion=#{illion}" | |
IO.puts "factor=#{factor}" | |
defp to_word(n) when n < unquote(:math.pow(10,factor*3)), do: to_word(div(n,unquote(:math.pow(10,(factor-1)*3)))) <> " " <> "#{unquote(illion)}" <> " " <> to_word(rem(n,unquote(:math.pow(10,(factor-1)*3)))) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment