wave.erl: an erlang script to read and write .wav files
Tuesday, 1st June, 2010
Please find below wave.erl, an erlang script for reading and writing .wav audio files. I am releasing it under the ISC license.
The script exports functions read/1, write/3 and write/2, and the wave record:
Using lists:map/2 with a named function
Tuesday, 11th May, 2010
When using a named function (i.e., rather than an anonymous function) with lists:map/2, it is necessary to use the form fun module:function/arity. For example, the module [1] will raise the error [2]:
[1]
-module(maptest). -export([test/0]). -export([double/1]). double(N) -> 2 * N. test() -> List = [1,2,3,4,5], lists:map(double, List).
[2]
1> c(maptest). {ok,maptest} 2> maptest:test(). ** exception error: bad function double in function lists:map/2
Module [3] works:
[3]
-module(maptest). -export([test/0]). %% -export([double/1]). %% not necessary double(N) -> 2 * N. test() -> List = [1,2,3,4,5], lists:map(fun double/1, List).
[4]
1> c(maptest). {ok,maptest} 2> maptest:test(). [2,4,6,8,10]
So the first argument of map — whether the function is named or anonymous — always starts with the keyword fun:
[5]
lists:map(fun(X) -> 2 * X end, List).
As an aside, it is not necessary to export the function in order to make it accessible to map (cf. [3]).
This is a summary of recent discussion on the erlang-programming-book Google group.
(Python and) Haskell (and Erlang) and chat
Sunday, 5th July, 2009
This is not really a post, more like a braindump. I need somewhere to offload all this so I can go to bed. I apologise for lack of context.
OK some context: I’m looking for a chat application I can use within a django-based website (and if I can’t find one, girding my loins to write one). Irrelevantly (or so I’d thought until a few minutes ago) I’m learning Haskell, and finding out about functional programming.
Haskell:
Erlang:
- Erlang web development
- Functional programming at Facebook, a paper at the forthcoming conference Commercal Users of Functional Programming
- Google search for Facebook chat erlang