O'Reilly logo

Learning Elixir by Kenny Ballou

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calling functions

There's another issue I've so far been skirting over—the syntax of calling functions. Specifically, you may have seen some examples around in which calling a function does not use parentheses to denote the function call. For example, from our previous example, these are equivalent:

iex(3)> MyMath.square(4)
16
iex(4)> MyMath.square 4
16

Why, you ask, is this the case? Why do we have two different acceptable forms? Elixir has a lot of its roots in Erlang. But this is only, so far, as some basic syntax and the runtime. The syntax borrows fairly heavily from Ruby. Thus, there's some Ruby syntactical elements present throughout Elixir, and this happens to be one of the Ruby carry-overs.

As far as when to use one version of the syntax ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required