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

Joe Armstrong erlang@REDACTED
Sat May 31 19:53:35 CEST 2014


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/20140531/a35f44c9/attachment.htm>


More information about the erlang-questions mailing list