On Tue, Jul 02, 2002 at 10:36:45AM -0700, Erik Steven Harrison wrote: > > Fortunately, a little research, has clarified a good bit of my question for me. So I >think I can reposit it more clearly. Here goes. > > You all know what pass by reference is, right? And pass by value? Well, Algol 60 >(somewhat by accident, it seems) created a third passing semantic, which is just >plain bizzare. A Perlish example, then an explanation. > > my $a = 'foo'; > > pass_by_name ( sub { print $a} ); > > sub pass_by_name { > my $a = 'bar'; > &@_[0]; > } > > Now, I have trouble keeping Perl 6 and 5 straight, but what I think this does is >print 'foo', as the sub ref is a closure, and gets $a bound to it. Fair enough. > > But in pass by name, expressions passed to a function aren't evaluated until they >are used inside that function, and are evaluated in the context of the surrounding >function. In a pass by name environment, the above code would print 'bar' as the sub >isn't evaluated until it is used in pass_by_name, and then it gets pass_by_name's >value of $a. Understand? Isn't that weird? > > So, pass by name sort of went to the wayside in the history of language design >(Algol 60 passed chunks of the parse tree around to make all this possible). There >are benefits (Jensen's Machine is apparantly an example, but don't ask me what it is) >but no one has used it since Algol 68 because it's difficult to explain, and hard to >implement. > > Now that you understand the background, here is the impetus for my > question: Ruby has brought pass by name back into the mainstream with it's much >lauded iterators. A Ruby iterator is a block of code that objects can take and are >evaluated as you would expect in a pass by name environment. I haven't used Ruby, but >I am jealous of their iterators. So, my question is, now that we have seen that pass >by name has a practical use, and can be handled in a manner which doesn't confuse the >user, can we steal it, using Ruby as prior art? > Basically, do we get Ruby iterators? > > -Erik
I'm new to talking on this list, so please bear with me... What I see in this example is the same syntax as a closure, so how precisely does the interpreter determind whether you want this to be a closer or a pass-by-name call. Do you have an example of the perl-ish code that doesen't break the ideas of lexical scoping? (or am I just not seeing the subtle difference between your example and a closure?) -hachi