whencannot accept functions that returns Boolean values as conditions. Consider the following lines of code…
Helloand a function
hellothat takes two parameters of
age. So, based on age I am trying
IO.putsaccordingly. If you do so you will get an error saying….
macrosLets do that…
MyGuardsand make sure the module is top of the module
Helloso, the macros first gets compiled. Now compile and execute you will see the following output..
defguardis also a macro. You can also create private guards with
defguardp. Hope, you got the point here. Consider the following example.
defguardpshould 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
five, you can define the guard as following.
=~operator we can find whether the right sub-string present in left string or not..
ensure_compileto check whether the module is compiled or not…
Elixir.So in the
Blackodeis equivalent to
String.to_atom "Blackode"it converts it into
:BlackodeBut actually we need something like “Blackode” to Blackode. To do that we need to use
=does the pattern match for left and right side. We cannot do
[a, b, c] = [1, 2, 3, 4]this raise a
destructure/2to do the job.
nilvalue for remaining entries..
labeloption. The string of
labelis added at the beginning of the data we are inspecting.
|>pipe operations like following……
fnto define anonymous functions.
?operator to retrieve character integer codepoints.
iexenvironment , you can see a number increment every time you evaluate an expression in the shell like
v/1function which has been loaded by default..