when
cannot accept functions that returns Boolean values as conditions. Consider the following lines of code…Hello
and a function hello
that takes two parameters of name
and age
. So, based on age I am trying IO.puts
accordingly. If you do so you will get an error saying….macros
Lets do that…MyGuards
and make sure the module is top of the module Hello
so, the macros first gets compiled. Now compile and execute you will see the following output..defguard
is also a macro. You can also create private guards with defguardp
. Hope, you got the point here.
Consider the following example.defguard
and defguardp
should reside inside the module like other macros. It raises a compile time error, if some thing that don't fit in the guard clause section when
.three
or five
, you can define the guard as following.boolean
value.=~
operator we can find whether the right sub-string present in left string or not..ensure_compile
to check whether the module is compiled or not…Elixir.
So in the defmodule Blackode
example Blackode
is equivalent to :"Elixir.Blackode"
String.to_atom "Blackode"
it converts it into :Blackode
But actually we need something like “Blackode” to Blackode. To do that we need to use Module.concat
=
does the pattern match for left and right side. We cannot do [a, b, c] = [1, 2, 3, 4]
this raise a MatchError
destructure/2
to do the job.nil
value for remaining entries..inspect
and label
option. The string of label
is added at the beginning of the data we are inspecting.|>
pipe operations like following……output
&
like following..fn
to define anonymous functions.?
operator to retrieve character integer codepoints.iex
environment , you can see a number increment every time you evaluate an expression in the shell like iex(2)>
iex(3)>
v/1
function which has been loaded by default..