[erlang-questions] How to return all records in dets

Joe Armstrong erlang@REDACTED
Sun Jun 1 11:09:19 CEST 2014

On Sat, May 31, 2014 at 8:44 PM, <lloyd@REDACTED> wrote:

> Hi Joe,
> I've resorted to approach 0 many times and much appreciate the generous
> help I've received from the community. Indeed, response from the author of
> my Erlang bible is particularly awesome. I hope one day to be competent
> enough to play it forward.
> I also spend a great deal of time in the Erlang man pages. Problem is that
> I'm one of those soft-headed liberal arts types. So, I often find the man
> pages near incomprehensible (and not only Erlang). Yes, I perhaps should
> have taken more math classes to grasp the elegant concision. But my mind
> doesn't seem to be wired that way.
> I can't tell you how many times I've looked at the foldl/n docs and tried
> to understand what the hell is going on. I get the general drift, but can't
> bring it down to useful code. There's just too much inside-baseball.
> As a self-taught-from-books-and-web Erlang aspirant, I find concrete
> examples and well-written tutorials most helpful. This gives me leverage to
> apply your approach 3. In general, the concepts of Erlang are simple enough
> once I grasp them. In fact, I marvel at the pragmatic elegance. Your books
> provide particularly lucid explications. But the man pages? My how I wish I
> had the time and chops to write a parallel set for noobies.
> Indeed, would it be helpful if I walked through and commented on the man
> doc items that give me headaches?

Absolutely - There is a problem here - which I think should be addressed as
soon as
possible - "It is not easy to common and ask question about man pages" -
I'd really like to see commenting in the style of the real world Haskell

If you're interested take a look at
http://book.realworldhaskell.org/read/types-and-functions.html - in
particular look at how comments are added to the text.

The erlang man pages are generated from XML so a commenting system should be
easy to make.

I'd like to see questions about the man pages discussed "inside the man
if you see what I mean - not "outside the man pages" (ie here)


Folds are very common there are the "iterators with an accumulator"

In an imperative language you might say

    state = state0
    for(i in x){
        state = update(state, f(i))

In erlang this is a fold

    fold(F, State0, X)

F is a function of I and State which returns a new state, and I iterates
over the values in X


   fold(fun(I, S) -> I + S end, 0, L)

is the same as

    S = 0;
    for(I in L){
       S = S + I

This is a very common programming pattern



> Many thanks again for your kind help,
> Lloyd
> -----Original Message-----
> From: "Joe Armstrong" <erlang@REDACTED>
> Sent: Saturday, May 31, 2014 1:53pm
> To: "Lloyd Prentice" <lloyd@REDACTED>
> Cc: "Erlang-Questions Questions" <erlang-questions@REDACTED>
> Subject: Re: [erlang-questions] How to return all records in dets
> The thing to Google for is "dets man erlang" - which should get you the man
> page
> (even better is to store the man pages locally and do "erl -man dets")
> You want to "list" all records (I'm not sure what list means here - it
> might mean
> "print" or "make a list of").
> To make a list of all records you could say:
>    dets:foldl(fun(X, L) -> [X|L] end, [], Name)
> (Most collections - ie dets, ets, dict, etc. offer some kind of fold
> operation that
> traverses all objects in the collection)
> To print all records
>   dets:traverse(Name, fun(X) ->
>                            io:format("~p~n",[X]),
>                            continue
>                       end)
> No need to worry about match specifications.
> The best place to start is usually by reading the man pages.
> Now that Erlang is is becoming popular you'll find a lot of incorrect
> solutions to problems posted on stackoverlow.
> Best approach is
>     0) ask an expert
>     1) read the man pages for the module, in question
>     2) experiment with the functions in the man pages in the shell
>     3) ask/tell this list if the manual pages are ambiguous or
> incomprehensible
>     4) search Google/stackoverflow
> Cheers
> /Joe
> On Fri, May 30, 2014 at 9:56 PM, <lloyd@REDACTED> wrote:
> > Hello,
> >
> > I'm cross-eyed from looking at match specifications. All I want to do is
> > list all records in my small dets table. I once ran across a very neat
> > query to accomplish that, but for the life can't Google it up.
> >
> > Can some kind soul give me a query that works?
> >
> > Many thanks,
> >
> > LRP
> >
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140601/0746aa69/attachment.htm>

More information about the erlang-questions mailing list