Skip to content

Instantly share code, notes, and snippets.

defmodule Combinations do
# See http://rosettacode.org/wiki/Combinations#Erlang
def comb(0, _), do: [[]];
def comb(_, []), do: [];
def comb(n, [h | t]) do
lc = for l <- comb(n - 1, t), do: [h | l]
@Andy-Richards
Andy-Richards / idea.log
Created January 15, 2014 16:11
Intellij-erlang debug log
This file has been truncated, but you can view the full file.
2014-01-15 15:57:21,630 [ 0] INFO - #com.intellij.idea.Main - ------------------------------------------------------ IDE STARTED ------------------------------------------------------
2014-01-15 15:57:21,665 [ 35] INFO - #com.intellij.idea.Main - IDE: IntelliJ IDEA (build #IC-133.609, 14 Jan 2014 00:00)
2014-01-15 15:57:21,665 [ 35] INFO - #com.intellij.idea.Main - OS: Linux (2.6.32-358.18.1.el6.x86_64, amd64)
2014-01-15 15:57:21,665 [ 35] INFO - #com.intellij.idea.Main - JRE: 1.7.0_21-b11 (Oracle Corporation)
2014-01-15 15:57:21,665 [ 35] INFO - #com.intellij.idea.Main - JVM: 23.21-b01 (Java HotSpot(TM) 64-Bit Server VM)
2014-01-15 15:57:21,671 [ 41] INFO - #com.intellij.idea.Main - JVM Args: -Xms128m -Xmx750m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=96m -ea -Dsun.io.useCanonCaches=false -Djava.net.preferIPv4Stack=true -XX:+UseCodeCacheFlushing -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -XX:+HeapDumpOnOutOfM
@Andy-Richards
Andy-Richards / gist:7785272
Created December 4, 2013 10:15
Dynamically generate funs from a list of fun names with a __before_compile__ hook
defmodule A do
defmacro __before_compile__(_env) do
Enum.each(["a", "b"], fn(name) ->
quote do
def unquote(name), do: unquote(name)
end
end)
quote do
defmodule MyMacro do
defmacro do_something(query) do
quote do
args = String.split(unquote(query))
fun = fn(arg) -> IO.inspect var!(unquote(binary_to_atom(arg))) end
Enum.each args, fun
end
end
end
@Andy-Richards
Andy-Richards / gist:6916317
Created October 10, 2013 10:31
both statetements error with ....expected var!(v) to expand to an existing variable or be a part of a match
% from my unit tests
foo = 10
assert 10 == my_macro(:foo)
assert 10 == my_macro("foo")
% macro