This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin = "HELLO" | |
spawn(fn -> | |
raise ArgumentError, message: "Unsupported or invalid status #{bin}" | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(1)> bin = "HELLO" | |
"HELLO" | |
iex(2)> raise ArgumentError, message: 'Unsupported or invalid status #{bin}' | |
** (ArgumentError) Unsupported or invalid status HELLO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(1)> raise 'foo' | |
** (ArgumentError) argument error | |
:erlang.apply('foo', :exception, [[]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
λ iex -S mix | |
iex(1)> Dbg.trace(self(), :call) | |
{:ok, [{:matched, :nonode@nohost, 1}]} | |
iex(2)> Dbg.call(Mix.Task, :stack) | |
{:ok, [{:matched, :nonode@nohost, 20}, {:saved, 1}]} | |
iex(3)> args = [] | |
[] | |
iex(4)> Mix.Task.run("run", ["test/fixtures/help_cmd.exs"|args]) | |
:noop | |
iex(5)> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(1)> OptionParser.parse(["--hello", "world"]) | |
{[hello: "world"], [], []} | |
iex(2)> OptionParser.parse(["--hello", "world"], switches: [hello: [:string]]) | |
{[hello: "world"], [], []} | |
iex(3)> OptionParser.parse(["--hello", "world"], switches: [hello: [:string, :optional]]) | |
{[hello: nil], ["world"], []} | |
iex(4)> OptionParser.parse(["--hello=world"], switches: [hello: [:string, :optional]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
λ iex my.ex | |
Erlang/OTP 17 [erts-6.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace] | |
Interactive Elixir (0.13.3-dev) - press Ctrl+C to exit (type h() ENTER for help) | |
iex(1)> use My | |
nil | |
iex(2)> 3&&4 | |
81.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Beamie.Store.RiakHTTP do | |
def put(bucket, key, value) do | |
IO.puts "storing value #{inspect value} with key #{key} in bucket '#{bucket}'" | |
put_req(bucket, key, value) | |
end | |
def get(bucket, key) do | |
IO.puts "retrieving value for key #{key} from bucket '#{bucket}'" | |
get_req(bucket, key) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# attr.exs | |
# using module attributes as compile-time constants | |
defmodule M do | |
@constant 13 | |
def a, do: @constant | |
@constant 44 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iex(3)> """abc | |
...(3)> bcd""" | |
...(3)> """ | |
...(3)> """ | |
...(3)> """ | |
...(3)> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Bag do | |
defstruct store: %{} | |
def new do | |
%Bag{} | |
end | |
def put(%Bag{store: store}, thing) do | |
%Bag{store: Map.update(store, thing, 1, &( &1 + 1))} | |
end |