Short Functions

David Herman dherman at mozilla.com
Mon May 23 19:10:19 PDT 2011


IANA Rubyist, but I *think* the goal was for blocks to be downwards-only, so that upvars could live on the stack and everything could be nice & speedy. So they had to syntactically restrict blocks to enforce that they couldn't outlive the frame in which they were created.

As Brendan says, that's just restricting expressiveness to make optimization easier. We don't need to do that, and if we work a little harder, we can still stack-allocate in many cases.

Dave

On May 23, 2011, at 8:38 AM, Jason Orendorff wrote:

> On Sun, May 22, 2011 at 7:35 PM, Brendan Eich <brendan at mozilla.com> wrote:
>> On May 22, 2011, at 5:21 PM, Isaac Schlueter wrote:
>>> Yes, I guess we are pushing opinions at each other.  I'd say that they
>>> are that bad.
>>> 
>>> I have experience only with Ruby, not SmallTalk or E.  Maybe they're
>>> handled better in the other two?
>> 
>> Could you say more than "that bad", precisely how and why and wherefore, an example or three, about your Ruby experience?
> 
> Oh, I disliked Ruby blocks at first because tutorial after tutorial
> left me with no real understanding of the feature. I was totally
> unable to predict what would happen in any slightly unusual case. I
> had to try it and see. I blame myself for looking at tutorials when I
> should've been looking at source code, but I also blame the tutorials
> for taking the attitude "and if you call a block after the enclosing
> method exits, um.... hey look, cartoon foxes!"
> 
> Today I understand continuations better. I would be able to guess the
> answers (with fewer trials, not zero) and I wouldn't be so frustrated.
> Not everybody has that background though.
> 
> Another possible gripe is that Ruby blocks are syntactically special.
> They're not expressions.
>  [1, 2, 3].collect {|i| i + 1}  # ok
>  x = {|i| i + 1}  # syntax error
> This compounds the first problem by making them a bit harder to play
> with in the REPL. In Smalltalk, as in your straw-man, blocks are just
> expressions. That seems much better--but I'd like to know why Ruby
> went the other way.
> 
> -j
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list