0
iex(5)>  IO.puts("hello world")
hello world
:ok
iex(6)> :math.exp(3)
20.085536923187668

When calling IO.puts, no need ":" before IO.

when calling :math, need ":" before math.

Why?

Chen Yu
  • 3,955
  • 1
  • 24
  • 51
  • Does this answer your question? [Is Elixir's module an atom?](https://stackoverflow.com/questions/29674102/is-elixirs-module-an-atom) – Daniel Jun 21 '22 at 17:47

2 Answers2

1

The colon is used to call an erlang function. So, if you see a function in the erlang docs that you would like to call, then you have to precede the name with a colon. Functions provided by Elixir are not preceded by a colon.

7stud
  • 46,922
  • 14
  • 101
  • 127
1

Module names must be atoms.

In , the literal starting with a capital letter is an atom. All domestic modules are named starting with a capital letter.

modules are starting with a small letter, :math is an atom, math is not, in . In , math is already an atom.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
  • "the literal starting with a capital letter is an atom" - more accurately, it's assumed to be a module name and is *converted* to an atom that is prefixed with `Elixir.`. – Adam Millerchip Jul 08 '22 at 17:30
  • TIL, they're actually aliases https://stackoverflow.com/questions/29674102/is-elixirs-module-an-atom#comment47501637_29674200 – Adam Millerchip Jul 08 '22 at 17:35