Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir Atoms and its different forms

Tags:

elixir

So, as a newbie to Elixir lang, I am thoroughly confused with : (colons) on both sides of a variable!

:status is an atom, but we also find in maps or structs stuff like so:

%{
   kkey: "success"
 }

Is the kkey an atom? If so, how is this different from :kkey, the standard way of declaring an atom!

Another example to drive home the point:

IO.inspect(some_variable, label: "value of some_variable")

In this example, is label: considered an atom?

Furthermore, in Keyword List are all keys atoms?

Appreciate clarifications. Thanks!

like image 452
iyerland Avatar asked Nov 17 '25 09:11

iyerland


1 Answers

Your assumptions are correct:

%{
  kkey: "success"
}

is equivalent to:

%{
 :kkey => "success"
}

For more information about Keyword lists, read the documentation.

like image 182
zwippie Avatar answered Nov 19 '25 01:11

zwippie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!