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 SimpleFib do | |
def fib(0), do: 0 | |
def fib(1), do: 1 | |
def fib(n) do | |
do_fib(n, 2, 1, 0) | |
end | |
defp do_fib(x, x, prev, prevprev) do | |
prev + prevprev | |
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
defp planting_operations_only do | |
from operation in Operation, | |
where: operation.operation_type == "planting", | |
preload: :variety | |
end | |
def crop_plan_preloads(query) do | |
from q in query, | |
preload: :crop, | |
preload: :fields, |
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 ImportExample do | |
# on this line Enum is not imported, yet. | |
import Enum #imports are not Module-wide. they only apply below the import. | |
def all_funcs do | |
map([1,2,3], fn n -> n + 1 end) #map is from Enum | |
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 Trier do | |
require IEx | |
def thing do | |
x = 0 | |
try do | |
1 / x | |
rescue | |
e in ArithmeticError -> |
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
def passwords_match?(_x, _x), do: true | |
def passwords_match?(_, _), do: false | |
# causes the following warning... | |
# registration.ex:61: warning: the underscored variable "_x" appears more | |
# than once in a match. This means the pattern will only match | |
# if all "_x" bind to the same value. If this is the intended behaviour, | |
# please remove the leading underscore from the variable name, | |
# otherwise give the variables different names |
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
def f(x) when x in [:ok, :bien, :guay] do | |
:ok | |
end | |
def f(_) do | |
:mal | |
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
def f(:ok), do: :ok | |
def f(:bien), do: :ok | |
def f(:guay), do: :ok | |
def f(_), do: :mal |
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
#!/bin/bash | |
# This script installs Erlang 17.5 from source and Elixir 1.0.4 | |
# from precomplized zip. Installation took approximately | |
# 40 minutes with a crappy computer and crappy internet connetion. | |
# This script should work (read: was only tested) on Mint | |
# Rebecca 17.1, but honestly should work on most Linux debian distros. | |
# INSTRUCTIONS: | |
# Pull this into a directory that will persist. (not tmp) |
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
elbow@elbow-K55N /usr/local/lib/erlang $ iex | |
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] | |
*** ERROR: Shell process terminated! (^G to start new job) *** | |
=INFO REPORT==== 13-Apr-2015::20:02:11 === | |
application: elixir | |
exited: {bad_return, | |
{{elixir,start,[normal,[]]}, | |
{'EXIT', |
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
/* | |
This is an enum. In Rust, an enum is a type which can only | |
be in one of a finite category of states; the states with which | |
the enum was defined. | |
Each of these states may or may not "wrap" an already existent type. | |
For instance, a variable that is of the type FizzedEnum can be in | |
the one of the following states: FizzBuzz, Fizz, Buzz, or Int(isize). | |
In the case of Int(isize), the FizzedEnum is in a state that wraps | |
an integer of type isize. |