--

On 02 Jul 2002 09:56:46 +010  
 pdcawley summed:

>  Ruby iterators
>
>    Ruby interators were the subject of Erik Steven Harrison's post, which
>    also referred to 'pass by name' and 'the Jensen Machine', and wanted to
>    know 'the Perl 6 stance on the matter'. Nobody has yet stepped up to the
>    plate on this one and, speaking personally, I'm not entirely sure I've
>    understood the question.

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


Is your boss reading your email? ....Probably
Keep your messages private by using Lycos Mail.
Sign up today at http://mail.lycos.com

Reply via email to