[erlang-questions] Question on Diagraph module

Hynek Vychodil <>
Sat Feb 2 11:57:35 CET 2008


On Feb 2, 2008 2:46 AM, Balu Balasubramanian <> wrote:

>
> Thanks, Bengt.
> Makes sense. Yes, the shell did crash and got recreated with new process
> id. But I see that the variable binding for G is still valid.
> That raises one more question (not really related to digraph)
> When the shell (and in general any process) crashes won't it automatically
> forget the variable bindings  as well?


There is big difference between shell and any other process in normal
working application. Shell itself is one process which keep variable binding
different way than normal bindings in normal functions (and so variables are
binded only inside functions, not for whole process).
When you type some expression, expression is evaluated inside different
subprocess and this subprocess is reused until crash. When evaluating
subprocess crash, new one is created and used since that moment. Because
bindings are kept inside shell main process, they can survive evaluating
process crash. So behavior of shell is different from behavior of normal
processes. For example digraph:new is called from evaluating shell process
and digraph made they own ets tables with PID of evaluating process stored.
Then result graph object is saved in shell main process and when evaluating
process crash, graph disappear but graph record inside main shell process
binding storage don't. Shell only emulate variable bindings inside one
function this way. Shell can be made different way using try - catch but
there is other caveats. For example you would be able break shell main
process from evaluating expressions. (You can do it anyway in present
implementation by code loading and storing code reference in shell
bindings.)


>
>
> ----------------------------------------
> > From: 
> > CC: 
> > Date: Tue, 29 Jan 2008 09:52:55 +0100
> > Subject: Re: [erlang-questions] Question on Diagraph module
> >
> > Greeteings,
> >
> > Presumably you are getting the error because G is gone.
> >
> > I have never used digraphs but the manual page
> > (http://erlang.org/doc/man/digraph.html) says:
> >
> > "The digraph will, however, be deleted if the process that created the
> > digraph terminates."
> >
> > Your shell process, that created G, has just crashed.
> >
> >
> > bengt
> >
> > On Tue, 2008-01-29 at 08:16 +0000, Balu Balasubramanian wrote:
> >> Hi,
> >>
> >> I am new to Erlang!
> >>
> >> Can some one explain why I am getting the last error message (badarith)
> that I get with digraph module in stdlib.
> >>
> >> Erlang (BEAM) emulator version 5.5.4 [source] [64-bit]
> [async-threads:0] [kernel -poll:false]
> >>
> >> Eshell V5.5.4  (abort with ^G)
> >> 1> G=digraph:new().
> >> {graph,14,15,16,true}
> >> 2> digraph:info(G).
> >> [{cyclicity,cyclic},{memory,847},{protection,protected}]
> >> 3> digraph:info().
> >>
> >> =ERROR REPORT==== 8-Jan-2008::22:02:06 ===
> >> Error in process  with exit value:
> {undef,[{digraph,info,[]},{erl_eval,d
> o_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}
> >>
> >> ** exited: {undef,[{digraph,info,[]},
> >>                    {erl_eval,do_apply,5},
> >>                    {shell,exprs,6},
> >>                    {shell,eval_loop,3}]} **
> >>
> >> % the above error is obvious as digraph:info/0 is udnefined. But now,
> >>
> >> 4> digraph:info(G).
> >>
> >> =ERROR REPORT==== 8-Jan-2008::22:02:08 ===
> >> Error in process  with exit value:
> {badarith,[{digraph,info,1},{erl_eval
> ,do_apply,5},{shell,exprs,6},{shell,eval_loop,3}]}
> >>
> >> ** exited: {badarith,[{digraph,info,1},
> >>                       {erl_eval,do_apply,5},
> >>                       {shell,exprs,6},
> >>                       {shell,eval_loop,3}]} **
> >>
> >> % Can some one please explain the above badarith error? Are there known
> issues with the digraph module?
> >>
> >> 5> init:script_id().
> >> {"OTP  APN 181 01","R11B"}
> >> 6>
> >>
> >>
> >> Thanks
> >> Balu
> >>
> >>
> >> _________________________________________________________________
> >> Connect and share in new ways with Windows Live.
> >>
> http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_012008
> >> _______________________________________________
> >> erlang-questions mailing list
> >> 
> >> http://www.erlang.org/mailman/listinfo/erlang-questions
> >
> > _______________________________________________
> > erlang-questions mailing list
> > 
> > http://www.erlang.org/mailman/listinfo/erlang-questions
>
> _________________________________________________________________
> Need to know the score, the latest news, or you need your Hotmail(R)-get
> your "fix".
> http://www.msnmobilefix.com/Default.aspx
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080202/d5e7f69e/attachment.html>


More information about the erlang-questions mailing list