|
|
|
|
|
by strmpnk
3873 days ago
|
|
I think it was for demonstration. The example certainly is a bit contrived but the general idea is that pattern matching in function heads is preferred over pattern matching in case expressions by most experienced Erlang developers I know and certainly by the author. It's not a hard rule but there are definitely times when giving a name to a set of patters is better than the anonymous case. Some other languages use things like let-in and with to achieve similar ideas but Erlang is a rather simple language so it just reuses function heads instead of nesting definitions. |
|
I've converted entire databases of mostly static data into nothing but a bunch of exact-match function head signatures and let one of the fastest paths in the VM be my "query planner".
It's insanely fast (at the expense of compile time) and the generated code is really easy to read, trace, and debug.