From: Benoit Cerrina Date: 2002-01-09T17:41:12+09:00 Subject: Re: dynamic variable "ts" wrote in message news:200201080943.g089hRt14831@moulon.inra.fr... > >>>>> "B" == Benoit Cerrina writes: > > B> in the ruby source, I don't understand why in the rb_dvar_curr > B> method the iteration over the dynamic variable stops at the first > B> variable with a null id while the dvar_asgn_internal with curr == true will > B> stop only at the > B> second variable with a null id? > > > Well, if you want to know such things, it's best to have a node dumper I'm writing one for jruby trying to understand all the nodes, by the way is there some kind of doc (even partial) on the ruby nodes, all the name are not exactly clear before hand even though once you know what it means you kind of get an idea of where the name came from. should I use NodeDump from pragmaticprogrammers or ii from Guy Decoux > (look in RAA you have some extensions) and look at parse.y (assignable() I've done that (both with jruby and MRI's code) which made me understand that those things existed and that they had to do with blocks. > for example). here a little example : I usually do this > > 1.times do |i| # here you have a NODE_DASGN_CURR > i = 12 # here you have a NODE_DASGN_CURR > 1.times do > 1.times do > 1.times do > i = 2 # here you have a NODE_DASGN > end > end > end > end > > If you try to assign a value to a variable, and this variable can be a > dynamic variable and don't exist (or exist in the curent level) then ruby > create a NODE_DASGN_CURR > > When rb_dvar_curr() is called it look *only* in the first level of dynamic > variable (each level (#times do in my example) are seperated with a null > id). If it's not found it create the id at the current level. that I understand but what surprises me is in dvar_assign_internal the code is dvar_asgn_internal(id, value, curr) ID id; VALUE value; int curr; { int n = 0; struct RVarmap *vars = ruby_dyna_vars; while (vars) { if (curr && vars->id == 0) { // curr means we were called from dvar_asgn_curr n++; if (n == 2) break; //why 2 why not break at the first null } > > In my example, the first NODE_DASGN_CURR will create the dynamic variable > and assign a value, the second will only assign it a value > > When you have a NODE_DASGN this mean that a dynamic variable exist in a > previous level and in this case ruby don't test for the null id when it > try to retrieve it. > > > Guy Decoux > Thanks for the reply Benoit