[erlang-questions] *current* value?

YC yinso.chen@REDACTED
Wed Oct 17 23:51:27 CEST 2007


Great - thanks for the confirmation and explanation.

Cheers,
yc

On 10/17/07, David King <dking@REDACTED> 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.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20071017/0e505980/attachment.htm>


More information about the erlang-questions mailing list