Erlang
I thought learning a more functional programming would be a good way to expand my programming language. I've only started yesterday, and it's been been rather rough.
For a "simple" application, I was planning to create a simple user-auth front-end for CouchDB (which what it lacks currently) in erlang, using YAWs as the webserver. I over estimated my understand of erlang as with less then idea error messages.
Here's some syntax if you're interested (I just copied an except from my current code):
get_ids(AllDocs) ->
Rows = key_find(AllDocs, rows),
if
Rows /= false -> get_ids(Rows, []);
true -> []
end.
get_ids([], CurrList) -> CurrList;
get_ids(Rows, CurrList) ->
[First|Rest] = Rows,
Id = key_find(First, id),
NewList = [Id|CurrList],
get_ids(Rest, NewList).
For most people of traditional languages, it's a bit weird syntax. I'm not going into depth to teach Erlang [there are better sources online than me
], but erlang allows multiple definitions of functions with the same name (including when they have the same number of parameters). To differenciate between which one gets called, the type of parameters (such as an empty list for the first parameter in the example above) and the order of definition allows erlang to determine which to call.
Although one annoying attribute about erlang that is increasingly evident is the syntax. Yes, the arrow syntax is pretty cool
, but the command terminators is a minigame in its own right. Most languages simply has a semicolon (;) after a command but Erlang follows these rules (maybe more):
- If it is the end of the function definition: use period (.)
- If more function definitions with the same prototype (aka, same function name and parameters): use semicolon
- If more commands follow the current one in the same block: use comma (,)
- If ending an if/case statement: use semicolon
- If ending the last if/case statement the entire if/case block: use no terminator.
As you can see, not fun.
On a side note. I failed to complete the yaws app in the desired 24 hour time period. Maybe I'll get back to it soon.