[erlang-questions] *current* value?

Sean Hinde <>
Thu Oct 18 00:15:48 CEST 2007

I would add a note of caution to your new found understanding. Using  
the process dictionary instead of passing parameters in the vast  
majority of normal erlang code can lead to the most incredibly  
strange bugs, and is almost never what you want.

The use as described in mnesia is a neat hack, and as far as I know  
it is the only place it is used in the whole of OTP.

Probably the best place to learn idiomatic erlang is from the sources  
to the rest of the (less complex) applications that come with OTP,  
and a few of the open source applications out there.


On 17 Oct 2007, at 22:51, YC wrote:

> Great - thanks for the confirmation and explanation.
> Cheers,
> yc
> On 10/17/07, David King < > wrote:
> Ah, I see. The process dictionary (when used in a read-only fashion,
> as you described earlier) is probably what you're looking for, then.
> That's how mnesia keeps track of your transactions in a construct
> like this:
>    mnesia:transaction(fun() ->
>                           mnesia:write(..)
>                         end), ...
> While you don't *specify* anything like current_transaction(),
> mnesia:write() implicitly refers to it, and it sets/gets it in the
> process dictionary. You could write a current_transaction() or
> something that would read it back out of the process dictionary. You
> could also design something like
>    Transaction=my_db:create_transaction(),
>    Data=my_db:read(Transaction,some_query()),
>    NewData=transform(Data),
>    my_db:write(Transaction,NewData).
>    my_db:commit(Transaction)
> Then you're passing your "current transaction" around rather than
> carrying it implicitly. I think that's cleaner. But if you wanted it
> to be implicit, you could use the process dictionary for it like
> mnesia does.
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

More information about the erlang-questions mailing list