What means the numbers the shell is returning?

Hi everyone!
I’m learning Elixir with the book “Elixir in Action” (Btw I’m loving the book!), and when I try the examples inside the iex, the console is returning a series of numbers when a function is declared, here is an example:

{:module, Circle,
<<70, 79, 82, 49, 0, 0, 5, 76, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 139,
0, 0, 0, 15, 13, 69, 108, 105, 120, 105, 114, 46, 67, 105, 114, 99, 108, 101,
8, 95, 95, 105, 110, 102, 111, 95, 95, …>>, {:area, 1}}

I assume that the information inside the brackets at the end is the function and the arity, but I don’t know what is that series of numbers in the middle. What does that mean?

Thanks!

Thats not when you define a function, thats when you define a module.

The second element in the tuple is the modules name, the third element is the byte code of the module and the last element corresponds to one (the last?) function that was defined in the module.

1 Like

Thanks!

It’s not about only the last function for example:

iex> defmodule Example do
iex>   def sample, do: :ok
iex>   3
iex> end
{:module, Example,
 <<70, 79, 82, 49, 0, 0, 4, 168, 66, 69, 65, 77, 65, 116, 85, 56, 0, 0, 0, 143,
   0, 0, 0, 15, 14, 69, 108, 105, 120, 105, 114, 46, 69, 120, 97, 109, 112, 108,
   101, 8, 95, 95, 105, 110, 102, 111, 95, ...>>, 3}

From documentation:

This macro defines a module with the given alias as its name and with the given contents. It returns a tuple with four elements:

  • :module
  • the module name
  • the binary contents of the module
  • the result of evaluating the contents block

Source: https://hexdocs.pm/elixir/Kernel.html#defmodule/2

4 Likes

Oh so we can do {_,_,_,val} = defmodule(...) :smiley:

Hmm … never had a need for this, but … yes, we can. That’s probably most useful in macros and not in a typical app.

Yep I can’t see why I would do that either!

1 Like