[erlang-questions] How to return all records in dets
Fred Hebert
mononcqc@REDACTED
Mon Jun 2 08:33:25 CEST 2014
On 06/01, Evgeny M wrote:
> My 2 cents as a more or less erlang noob on the documentation.
> Most of the docs on the standard modules is fine if you know basics about
> folds, maps, common data structures etc.
"Fine if you know them" tends to be a synonym of a 'reference manual',
in that it provides a reference (in case you need help remembering), not
tutorial.
> Some of docs, like docs on dets/ets/mnesia selects and matches are vague
> and need more examples.
That's where the Erlang documentation gets divided into a 'user guide'
and a 'reference manual'. For example, if you go into the margin on the
left, back to the top, you will see a menu like this:
User's Guide
Reference Manual
Release Notes
PDF
Top
The reference manual will contain something minimal like:
http://www.erlang.org/doc/man/mnesia.html#select-2 expecting you to know
about it, whereas if you go into the user guide, you get an actual tutorial:
http://www.erlang.org/doc/apps/mnesia/Mnesia_chap4.html#id74467 This one
has a few more examples than the reference manual.
> I for one still not sure why foldl on a table, as
> Joe Armstrong suggested, is better than match or select.
A fold is useful when you want to accumulate or reduce a state. For
example, if you were to accumulate the sum of all your red-headed
members, you could either use a 'select' pattern and make it return '1'
for every member, in which case you would end up with a potentially
large list you need to count the length of (or the sum of) to get your
result.
Using a fold, you iterate over the table and can accumulate the sum as
you go, never needing to build the intermediate list. That can help save
on memory if your data set is particularly large.
Regards,
Fred.
More information about the erlang-questions
mailing list