This file contains hidden or 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
# define a record, first attribute is considered the key | |
defrecord User, email: "", first: "", last: "" | |
# encapsulates mnesia calls | |
defmodule Database do | |
def create_schema do | |
create_table User | |
end | |
def find(record, id) do |
This file contains hidden or 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 DynaFuncs do | |
#this works - dynamic name with no args | |
{:ok, other_func_name} = Code.string_to_quoted(:half) | |
def unquote(other_func_name), do: IO.puts(1/2) | |
# but this doesn't work - static name with no args | |
def unquote(:one_third), do: IO.puts(1/3) | |
# and this works - static name with args |
This file contains hidden or 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 LoggerHandler do | |
use GenEvent | |
# Callbacks | |
def handle_event({:log, x}, messages) do | |
{:ok, [x|messages]} | |
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
NewerOlder