Behaviours in Erlang are similar to Java interface, but unlike Java interfaces they can have implementation
Example:
-module(mammal).
-export([describe/1]).
defmodule Crytopals do | |
use Bitwise | |
# http://en.wikipedia.org/wiki/Letter_frequency | |
@freq_english %{ | |
'a' => 8.167,'b' => 1.492,'c' => 2.782,'d' => 4.253,'e' => 12.702,'f' => 2.228,'g' => 2.015,'h' => 6.094,'i' => 6.966, | |
'j' => 0.153,'k' => 0.772,'l' => 4.025,'m' => 2.406,'n' => 6.749,'o' => 7.507,'p' => 1.929,'q' => 0.095,'r' => 5.987, | |
's' => 6.327,'t'=> 9.056,'u' => 2.758,'v' => 0.978,'w' => 2.360,'x' => 0.150,'y' => 1.974,'z' => 0.074, | |
} |
defmodule A do | |
defmacro left >| right do | |
quote do | |
:math.pow unquote(left), unquote(right) | |
end | |
end | |
end |
defmodule Repo do | |
use Ecto.Repo, adapter: Ecto.Adapters.Postgres, env: Mix.env | |
@doc "Adapter configuration" | |
def conf(env) do | |
a = parse_url url(env) | |
IO.inspect(a) | |
a | |
end | |
Randomized with seed 736044 | |
==> logger (exunit) | |
test/logger_test.exs:222: warning: variable pid is unused | |
................................................ | |
1) test translates Supervisor reports abnormal shutdown in simple_one_for_one (Logger.TranslatorTest) | |
test/logger/translator_test.exs:435 | |
Assertion with =~ failed | |
code: capture_log(:info, fn -> | |
trap = Process.flag(:trap_exit, true) |
require 'rspec' | |
require './lisp' | |
describe '#lisp_eval' do | |
describe "CHALLENGE 1" do | |
it "lisp_evaluates numbers" do | |
expect(lisp_eval("1")).to eq(1) | |
end | |
it "lisp_evaluates booleans" do |
%%% -*- coding: utf-8; Mode: erlang; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | |
%%% ex: set softtabstop=4 tabstop=4 shiftwidth=4 expandtab fileencoding=utf-8: | |
%%% | |
%%%------------------------------------------------------------------------ | |
%%% @doc | |
%%% ==Abstract Code Insertion== | |
%%% A method to get the abstract code representation directly from the | |
%%% binary beam module representation. | |
%%% | |
%%% Other methods could be used, but they are not as efficient. |
DEPS = $(CURDIR)/deps | |
DIALYZER_OPTS = -Wunderspecs | |
# List dependencies that should be included in a cached dialyzer PLT file. | |
# DIALYZER_DEPS = deps/app1/ebin \ | |
# deps/app2/ebin | |
DEPS_PLT = {{name}}.plt |
-module(spike). | |
-include("./deps/amqp_client/include/amqp_client.hrl"). | |
-export([start/1]). | |
start(Queue) -> | |
amqp_lifecycle(Queue). | |
amqp_lifecycle(Queue) -> |
require 'rspec' | |
module Anagram | |
FindAnagram = ->(word) do | |
words = File.readlines("/usr/share/dict/words") | |
dict = Anagram::Dictionary.(words) | |
dict[SplitSort.(word).join] | |
end | |
Dictionary = ->(words) do |