Sponsored by AppSignal
Would you like to see your link here? Contact us
Notesclub

Geeky If

13_geeky_if.livemd

Geeky If

import IEx.Helpers

Section

keyword = [{:do, :something}, {:else, :something}]
[do: :something, else: :something]
x = 42
42
if x == 42, do: :cool, else: :bogus
:cool
if(x == 42, do: :cool, else: :bogus)
:cool
if(x == 42, do: :cool, else: :bogus)
:cool
if(x == 42, [{:do, :cool}, {:else, :bogus}])
:cool
"""
def my_fun(arg1, arg2) do
  :something
end
"""

# same as -> do: :cool, else: :bogus
"def my_fun(arg1, arg2) do\n  :something\nend\n"
quote do
  if x == 42 do
    :cool
  else
    :bogus
  end
end
{:if, [context: Elixir, imports: [{2, Kernel}]],
 [
   {:==, [context: Elixir, imports: [{2, Kernel}]], [{:x, [], Elixir}, 42]},
   [do: :cool, else: :bogus]
 ]}
# {:if, [context: Elixir, imports: [{2, Kernel}]],
#  [
#     # have two elements
#    {:==, [context: Elixir, imports: [{2, Kernel}]], [{:x, [], Elixir}, 42]},
#    [do: :cool, else: :bogus]
#  ]}
nil
syntax_tree = v(9)
syntax_tree |> elem(2)
error: undefined variable "syntax_tree"
  #cell:v4u2lf6f4eqmjne3t3mqnaxpn4zkw6zf:1
syntax_tree |> elem(2) |> length
if(foo, do: bar)

if(foo, do: bar, else: baz)