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 Test do | |
def fred, do: 1 | |
end |
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 Macros do | |
defmacro test(do: body) do | |
quote hygiene: [vars: false] do | |
def meth(a,b), do: unquote(body) | |
end | |
end | |
end | |
defmodule UseMacro do | |
import Macros |
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 Listen.NewFSM do | |
use Daves.Fsm, register: {:local, :listen_fsm}, | |
initial_state: :start, | |
init_params: [] | |
@timeout 3*1000 | |
defrecord CallInfo, from: "", to: "", suspicious_segments: 0 |
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
# The simplest version is probably to use list concatenation. However, | |
# this version ends up rebuilding the list at each step | |
defmodule UsingConcat do | |
def flatten([]), do: [] | |
def flatten([ head | tail ]), do: flatten(head) ++ flatten(tail) | |
def flatten(head), do: [ head ] | |
end | |
# This version is more efficient, as it picks successive head values | |
# from a list, adding them to `result`. The trick is that we have to |
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
defrecord Poker.Card, face: 0, suit: "" do | |
def value(record) do | |
case record.face do | |
"A" -> 14 | |
"K" -> 13 | |
"Q" -> 12 | |
"J" -> 11 | |
"T" -> 10 | |
int -> int |
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 CheckDigit do | |
import Enum | |
@doc """ | |
Determine if a sequence of digits is valid, assuming the last digit is | |
a Luhn checksum. (http://en.wikipedia.org/wiki/Luhn_algorithm) | |
""" | |
def valid?(numbers) when is_list(numbers) 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
import :timer, only: [ sleep: 1 ] | |
defmodule Link1 do | |
def sad_method do | |
sleep 500 | |
exit(99) | |
end | |
def run do | |
spawn(Link1, :sad_method, []) |
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 A do | |
def c(name) do | |
IO.puts "In c(#{name})" | |
end | |
end | |
wrapper = quote do | |
defmodule Wrapper 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
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- xml -*- --> | |
<!DOCTYPE ref-class SYSTEM "local/xml/markup.dtd"> | |
<ref-class name="Array" id="ref:Array" super-class="Object"> | |
<mi:Class>Array</mi:Class> | |
<relies-on>each, <=></relies-on> | |
<p> | |
Arrays are ordered, integer-indexed collections of any object. | |
Array indexes start at 0, as in C or Java. A negative index is | |
relative to the end of the array; that is, an index of -1 |
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
defprotocol WhizBang do | |
def specific(_) | |
def common(_) | |
end | |
defrecord Foo, name: "foo" | |
defrecord Bar, name: "bar" | |
defmodule Common do | |
def common(arg), do: IO.puts "Common.common: #{inspect arg}" |