From: "David A. Black" Date: 2003-12-11T11:45:44+09:00 Subject: Re: Adjusting the Scope of Blocks Hi -- On Wed, 10 Dec 2003, Dan Doel wrote: > [ interesting Lisp remarks which I fully intend to go back ] > [ and look at again :-) ] > > Proc objects are the same way. Code + context. #call works like a > normal closure (same as calling the method in Scheme), while #?_eval > replaces some of the context. At the risk of repeating myself: yeah, but that's the part I don't like :-) Actually I think it is, for me, a lexical-scope thing. Guy's example, or something like: obj.instance_eval { stuff } where it's all visible and lexically scoped together, doesn't bug me at all. It only starts feeling "trick"-like when the fact that the block is going to be instance_eval'd in obj's self context isn't manifest. OK, trying to zero in on this, here's a case. What if I *want* to use a locally defined method in a block? For example: def x; [1,2,3]; end obj.some_method { x } # I want the block to evaluate to [1,2,3] # if called or yielded to. That's what I # mean by 'x'. Now, if #some_method's class happens to have an #x method, #some_method can sort of hijack my call to #x. But I shouldn't know that or have to know it. If my "x" is going to be eval'd as a method call other than the one I thought it was, I want to be in on the deal and send it as an eval string. It reminds me a bit of things that depend on coordination (and therefore coupling) of local variable names between methods. It also seems to be predicated on a somewhat arbitrary variable/method-call split; if I'd done x=[1,2,3] above, instead of defining #x, 'x' wouldn't be vulnerable. > In some sense it is. self.instance_eval is a no-op with respect to > Strings passed in. self.instance_eval is a no-op as long as you're > just talking about a collection of code. It's only not a no-op when > you take context into account. (I think that makes it a sometimes-op :-) > [...] > >I may have passed over that thread... I'll look again. > > > > > The subject at the top of the thread was: Re: Controlled Block > Variables You actually replied to my first post about it basically > saying you didn't like the idea of blocks-as-just-code. :) Then > nothing after that so maybe you didn't read anything else. Yeah, I looked up the thread and found that I had participated in it and forgotten. Old age, you know :-) David -- David A. Black dblack@wobblini.net