2. about elixir
a functional meta-programming aware language built
on top of the Erlang VM
dynamic language with flexible and homoiconic syntax
supports polymorphism via protocols (similar to
Clojure's), dynamic records, aliases and first-class
support to associative data structures
full Erlang's power : concurrent, distributed, fault-
tolerant applications with hot code upgrades
3. History
2011/4 0.3.0: Ruby like object system
... Clojure inspired!
2011/12 0.4.0: Reborn! abandon object system and
add ‘true macro’
0.5.0: first major release!
0.6.0: now!
5. deprecated
loop/recur → use named function
Module.function_defined/1 → Module.defines?/1
File.read_info/1 → File.stat/1
__LINE__, __FUNCTION__ → __ENV__.line,
__ENV__.function
6. update: match syntax
--- old --- --- new ---
case r do case r do
match: [x,x] [x,x] -> x*2
x*2 _ -> true
match: _ end
true
end
7. update: match syntax more!
available match syntax in
cond/function!
function do
cond do
0 -> true
0 -> true
1 -> false
1 -> false
end
end
8. deprecate loop, used named
functions to recur instead
The reason for deprecating loops is two fold:
1) It reduces the number of special forms. Special forms
usually allow a variable number of arguments and have
special scoping rules and they cannot be overridden or
removed;
2) Anonymous looping is highly uncommon in Erlang and
slower than if we loop using named functions;
loop may be added back in the future as a non special form.
(commit in 7728f3d630)
9. loop/recurについて、大事な事
なので日本語で失礼します
二重loop/recurどうよ?
recurはloopの中のパターンマッチで複数箇所に書けるので、ど
のloopに再入するか決められない。
二重loop/recurと関係ないけど、f = function do m, 0 -> 0; m, 1 -
> 1; m, x -> m.(m, x-1) + m.(m, x -2) end; f.(f, 30)とかでよくね?
λ最高
みたいなやりとりが issue #215で行われた事が関係しているか不
明
10. enhancement: list (and
binary!) comprehension
Syntax:
(lc|bc) var (inlist listexp|inbits bitexp), Binary comprehension is 'bc' keyword
selector, do: exp bc <<y>> inbits "pta", do: <<y,y>>
List comprehension is 'lc' keyword → "ppttaa"
lc x inlist [:achan,:ksyk,:nocchi], <<y>> bc y inlist 'pta', do: <<y,y>>
inbits "pta", do: [x, <<y>>]
→“ppttaa”
→[[:achan,"p"],[:achan,"t"],[:achan,"a"],
[:ksyk,"p"],[:ksyk,"t"],[:ksyk,"a"], lc x inlist :lists.seq(1,100), rem(x,3) ==
[:nocchi,"p"],[:nocchi,"t"],[:nocchi,"a"]] 0, do: x
→[3,6,9,12,15,18,21,24,27,30,33,36,
39,42,45,48,51,54,57,60,63,66,69,72,
75,78,81,84,87,90,93,96,99]
11. tools: mix
a build tool
new : create project(with :application behavior)
compile: build(code and OTP .app file)
run: compile and run
test: run and test(ExUnit)
iex: invoke iex, include a path under development
modules
12. tools: iex
helpful cli for elixir
c: compile
h: history
d: document help
d(module): function list
d(module, function, arity): doc for module.function/arity
m: module inspection