start | find | index | login or register | edit | ||
erlang-notes
by earl, 6444 days ago
- variables are Uppercased (e.g. X, Y, Foobar, Point)- atoms (literal symbols) are lowercased (e.g. x, y, foobar, point) - atoms may be enclosed in '...' (e.g. 'I am an atom', '+'); note that 'a' == a - {...} is for tuples, components are seperated via , (e.g. {point, {x, 42}, {y, 10}} - [...] is for lists, elements are seperated via , (e.g. [1, 2, 3, 4]) - strings ("...") are shorthand for lists of latin1 character codes - $c is for characters; so "foo" == [$f,$o,$o] == [102,111,111] - <<...>> is literal binary data (aka bit syntax) - = does pattern matching: lhs is matched against rhs (one-sided unification); so lhs may contain variables, rhs must not. return value of a successful match is rhs - _ is a wildcard pattern - [H|T] matches H against a list's head, and T against its tail. matching multiple leading elements is possible: [X1,X2,X3|XS]. note that [X|[Y|[Z|T]]] equals [X,Y,Z|T] and [X|[Y|[]]] equals [X,Y]. - pattern=Name binds a (sub-)pattern to a name (e.g. {point, {x, 42}=X, _} binds X to {x,42} -- analog to haskell's @) - list comprehension: [ F(X) || X <- L ] - reifying a function: fun Module:FuncName/Arity (e.g. lists:map(fun tuple_to_list/1, [{a,b},{c,d}])) - anonymous function abstraction: fun(X,Y,Z) -> ... end. E.g.: 1> lists:map(fun(X) -> 2 * X end, [1,2,3,4]). - erl shell: help(): gives a help of all shell functions b(): displays all vairable bindings f(): unbinds all variables f(X): unbinds variable X c(File): compiles and loads code in File regs(): information about registered processes |
search 39 active users
backlinks (more) none, yet recent stores (more) echo earlZstrainYat|tr ZY @. |
|
earl.strain.at • esa3 • online for 8662 days • c'est un vanilla site |