From: Robert Klemme Date: 2005-03-16T16:24:48+09:00 Subject: Re: eval/binding question "Stefan Kaes" schrieb im Newsbeitrag news:4237CBC1.9070209@gmx.net... > Yukihiro Matsumoto wrote: > > >Hi, > > > >In message "Re: eval/binding question" > > on Wed, 16 Mar 2005 02:45:41 +0900, Stefan Kaes writes: > > > >|In the real environment, the names of the locally assigned variables can > >|not be determined in advance, of course. > > > >I'm sorry to say you can't pre-compile eRB allowing local variable set > >not determined in advance. I know allowing this will make your > >program 25% faster, but this also would make any other programs > >slower. > > > > > I fail to see why it would make other code slower. I am convinced with a > proper compiler implementation there would'nt be any speed difference > for local variables introduced via explicit assignment. Access to > predeclared variables would use an optimized access method, whereas > access to variable names whose declaration point cannot be determined by > statical program analysis would use a less efficient access method. I wonder in which cases this would be useful. This code is artificial, since one would never write test2 like you did: def test2 eval "x=25" print "x=#{x}\n" end If you write something similar but with a string coming from somewhere else def test2(s) eval s print "x=#{x}\n" end you know already that "s" must contain an assignment to "x". So it's not a problem to predeclare it IMHO. I don't really see which real world problems would be solved with a more complex lookup for locals, which would make the second variant succeed without the explicit declaration of "x". Kind regards robert