From: "J. Ryan Sobol" Date: 2006-01-14T05:29:53+09:00 Subject: Re: [QUIZ.SUMMARY] Dice Roller (#61) On Jan 13, 2006, at 3:15 PM, J. Ryan Sobol wrote: > On Jan 13, 2006, at 3:03 PM, James Edward Gray II wrote: > >>> Does eval parse @src for each call() message? >> >> Yes. You pass lambda() a block of code that is executed each time >> the code it called. > > Executed yes. But when is it parsed / checked for valid grammar, > syntax, etc.? Did you mean to say that the block of code is parsed > AND executed for each call() it receives? > > ~ ryan ~ obj = lambda { eval "#{2**10}" } (1..1_000_000).each do obj.call end $ time ruby test.rb real 0m26.046s user 0m24.377s sys 0m0.358s ------------------------------------------- obj = eval "lambda { #{2**10} }" (1..1_000_000).each do obj.call end $ time ruby test.rb real 0m3.132s user 0m2.895s sys 0m0.047s What a difference! I'll agree that parsing of eval's string happens on every call() message in the first example. :) ~ ryan ~