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

lloyd@REDACTED lloyd@REDACTED
Sat May 31 20:44:21 CEST 2014


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?

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
>





More information about the erlang-questions mailing list