|
|
||
code/lib_misc.erl
perms([]) -> [[]]; perms(L) -> [[H|T] || H <- L, T <- perms(L--[H])].
2> lib_misc:perms("123").
["123","132","213","231","312","321"]
よくわかんないので順を追って考えてみる。
perms("123"). は H|T] || H <- "123", T <- perms("123"--[H])]. で、組み合わせは以下の3通り。
H: "1", T: perms("23")
H: "2", T: perms("13")
H: "3", T: perms("12")
perms("23"). は H|T] || H <- "23", T <- perms("23"--[H])]. で、組み合わせは以下の2通り。
H: "2", T: perms("3")
H: "3", T: perms("2")
perms("3"). は H|T] || H <- "3", T <- ]?. で、これは ["3"] となる。perms("2"). も同様なので perms("23"). は以下のようになる。
["23", "32"]
一つ前に戻って当てはめていく。
H: "1", T: ["23","32"] H: "2", T: ["13","31"] H: "3", T: ["12","21"]
なので、
["123","132","213","231","312","321"]
となる。
気づいたら前回の更新から4ヶ月以上経ってた。
会社にあったプログラミングErlangを借りてきた。おもしろいね、この本。
いままでWebにある英語のドキュメントを読んでたけど、日本語だとやっぱ楽だ・・。
そろそろ整理が必要になってきた。
Expr1,
...,
ExprN
Guard1;...;GuardN
Name(Pattern11,...,Pattern1N) [when GuardSeq1] -> Body1; ...; Name(PatternK1,...,PatternKN) [when GuardSeqK] -> BodyK.
if GuardSeq1 -> Body1; ...; GuardSeqN -> BodyN end
あとcase, receive, fun, tryなども同様。
Bodyはa sequence of expressions.
GuardSeqはa sequence of guardで、さらにGuardはa sequence of guard expressions.
Name(Pattern1,...,PatternN)[when GuardSeq1] -> Body1.
-module(Module). -export(Functions).
Voluntas2008/06/18 11:33; は or で、 , は and で、 . は end と覚えるのが早いです。
nitsuji2008/06/22 00:43なるほどー
Erlang processes are neither operating system processes nor operating system threads, but lightweight processes somewhat similar to Java's original “green threads” (the Java Virtual Machine now uses native threads). Like operating system processes (and unlike green threads and operating system threads) they have no shared state between them. The estimated minimal overhead for each is 300 words (4 bytes per word on 32-bit platforms, 8 bytes per word on 64-bit platforms), so many of them can be created without degrading performance (a benchmark with 20 million processes was tried[3]).
Erlang (programming language) - Wikipedia, the free encyclopedia
なんかわかるようでわかんないのでgreen threadsというのを見てみる。
The Erlang virtual machine has what might be called 'green processes' - they are like operating system processes (they do not share state like threads do) but are implemented within the Erlang Run Time System (erts). These are sometimes (erroneously) cited as 'green threads'.
OSじゃなくてVirtual Machineが管理するのがGreen threadsというやつらしい。で、erlangのprocessは言わばgreen processesってところで、OSのプロセスみたいなんだけどErlang Run Time System (erts)で実装されていると。
なんかわかってきた。
つまりこのへんの軽量プロセス的なものの実装がerlangは優れてるってことなんですかね。
なんかおもしろそうなのでどういう仕組みなのかもうちょっと詳しく知りたいところではある。
LottaWhy do I bhoter calling up people when I can just read this!
utjzvhexvac8jRp <a href="http://ustobbmhuyui.com/">ustobbmhuyui</a>
macportsで入れた5.5.5(R11B-5)を使ってたんだけど、twitterでエラーメッセージの意味が分からんとぼやいていたら、エラーメッセージがカオスだと教えてもらったのでソースから最新版(R12B-2)を入れ直しました。
./configureでodbc link check failedとか言われたけどよくわかんないのでスルーした。
manは別にダウンロード&解凍して/usr/local/lib/erlangにコピーしたらerl -man ioとかできるようになった。
分けわかんなかったエラーメッセージは取ってないんだけど同じことをやったときのエラーメッセージは以下のようになって断然わかりやすくなった。
exception error: undefined function shell_default:format_temps/1