Erlang PostgreSQL client library
http://bitbucket.org/will/epgsql/overview/
http://glozer.net/src/epgsql_pool/(http://www.erlangatwork.com/2009/01/erlang-and-postgresql-redux.html)
http://bitbucket.org/will/epgsql/overview/
http://glozer.net/src/epgsql_pool/
-module(zeez2).
-export([main/1]).
main([A]) ->
L = list_to_integer(atom_to_list(A)),
zeez( true ,L, L).
zeez(true, 0, N) ->
io:format("~p~n", [zeez(z, N)]),
init:stop();
zeez(false, M, N) ->
io:format("~p~n", [zeez(space, M)]),
zeez(M-1 rem N =:= 0, M-1, N );
zeez(true, M, N) ->
io:format("~p~n", [zeez(z, M)]),
zeez(M-1 rem N =:= 0, M-1 , N ).
zeez(space, 0) ->
"Z";
zeez(space, N) ->
"-" ++ zeez(space, N-1);
zeez(z,0) ->
"Z";
zeez(z, N) ->
"Z" ++ zeez(z, N-1).
wk# erlc zeez2.erl wk# erl -noshell -s zeez2 main 10 "ZZZZZZZZZZZ" "---------Z" "--------Z" "-------Z" "------Z" "-----Z" "----Z" "---Z" "--Z" "-Z" "ZZZZZZZZZZZ" wk#
พิมพ์วันทั้งหมดที่มีในปีนี้
-module(cal).
-export([main/0]).
main() ->
StartSec = calendar:datetime_to_gregorian_seconds({{2009,1,1},{0,0,0}}),
EndSec = calendar:datetime_to_gregorian_seconds({{2009,12,31},{0,0,0}}),
run_calendar(StartSec,EndSec).
run_calendar(CurSec, EndSec) ->
{Date,_Time} = calendar:gregorian_seconds_to_datetime(CurSec),
io:format("~p~n", [Date]),
NewSec = CurSec + 60*60*24,
if NewSec =< EndSec -> init:stop() end,
run_calendar(NewSec, EndSec).
wk# erlc cal.erl
wk# erl -noshell -s cal main
{2009,1,1}
{2009,1,2}
{2009,1,3}
---
{2009,12,29}
{2009,12,30}
{2009,12,31}
Some highlights:
NIFs, write your own functions in C
Builds and runs on Windows 7
dialyzer can warn for some race conditions, and has a wx gui
The -on_load() directive can be used to run a function when a module is loaded.
Emacs erlang-mode improvements.
Materials from the Erlang User Conference 2009 and Tutorials Workshop at the EUC2009 are now available on our website:
- The presentation slides from the EUC2009 are available (http://www.erlang-factory.com/conference/ErlangUserConference2009/talks)
คำถาม
1> Pythag = fun(N) -> [ {A,B,C} ||
A <- lists:seq(1,N),
B <- lists:seq(1,N),
C <- lists:seq(1,N),
A= Pythag(100).
[{3,4,5}, {5,12,13}, {6,8,10},
{7,24,25},{8,15,17}, {9,12,15},
{9,40,41}, {10,24,26}, {12,16,20},
{12,35,37}, {15,20,25}, {15,36,39},
{16,30,34}, {18,24,30}, {20,21,29},
{21,28,35}, {24,32,40}]
ฟังก์ชันสำหรับสร้าง Anagram
Foo = fun(X) -> Fun = fun([],F) -> [[]]; (L,F) -> [[H|T] || H <- L, T <- F(L--[H],F)] end, Fun(X, Fun) end.
ทดสอบ