From: Logan Capaldo Date: 2006-01-14T05:09:22+09:00 Subject: Re: [QUIZ.SUMMARY] Dice Roller (#61) On Jan 13, 2006, at 2:57 PM, J. Ryan Sobol wrote: > On Jan 12, 2006, at 10:22 AM, Christian Neukirchen wrote: > >> Matthew Moss writes: >> >>> @dice = eval "lambda { #@src }" >>> >>> The morphed express is saved away in a lambda, which allows >>> Christian to >>> reevaluate the expression repeatedly without performing those >>> substitutions >>> every time roll is called. >> >> I could have evaluated @src each time without substituting anew, >> but a >> lambda only makes it need to *parse* once. > > Hey Christian, > > I didn't have time to write my own solution to quiz #61, so I'm > going over yours, which is similar to what I was kicking around in > my head. Unfortunately, I confused by your eval statement, which > is wrapped over a new Proc object. Instead, why not wrap the > lambda around the eval like so? > > @dice = lambda { eval @src } > > The both _seem_ to produce the same output, yet conceptually, my > approach makes more sense to me. Perhaps I'm missing something > crucial in my statement like... > > Does eval parse @src for each call() message? Or does the parsing > happen on initialization of the Proc (like I would expect)? I > suppose I could trace the execution using the debugger, but I'm > unaware how to step inside a Kernel method like eval or lambda with > it. > > ~ ryan ~ > @dice.call has eval parse @src everytime (@src may have changed). By doing something like eval "lambda { #{@src} }" you parse @src once and get back a lambda.