Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Created April 28, 2015 21:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmarreck/276a00f4a30ddf5dd5e6 to your computer and use it in GitHub Desktop.
Save pmarreck/276a00f4a30ddf5dd5e6 to your computer and use it in GitHub Desktop.
elixir dynamic method definitions?
[ 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