From: Paul Lutus Date: 2006-09-11T11:45:22+09:00 Subject: Re: Struggling with Blocks Logan Capaldo wrote: > On Mon, Sep 11, 2006 at 07:45:28AM +0900, Paul Lutus wrote: >> There is a need for both "do" and "begin" blocks. There is a need to >> distinguish syntactically between a block that must be fed with items, >> and one that must not be fed with items. To combine "do" and "begin" >> would lead to syntactical ambiguity ... and surely then someone would ask >> why the two purposes of "do" were not more clearly distinguished in the >> syntax. >> >> If "do" and "begin" were to be merged, it would be a little like the >> ambiguous use of "<<" in C++. In one context, it shifts bits: >> >> int x = 1,y; >> >> y = x << 4; // y = 16 >> >> In another context, "<<" inserts items into a stream: >> >> iostream x; >> bool y; >> >> y = x << 4; // y = true if the operation was successful >> >> See the problem? Without my clear declarations directly above each case, >> you would have a hard time distinguishing cases that use the same syntax. >> This would make program listings hard to interpret and debug (a fact in >> C++). >> >> The multiple uses of "<<" in C++ is a well-known example, but the point I >> am making is that it's important to avoid ambiguous syntax in language >> design. "do ... end" always has a stream, and when the stream is >> exhausted, the block exits. "begin ... end" never has a stream. It's easy >> to remember and easy to read. >> >> The end result of responding to every request for creative syntax >> variations is called ... umm ... "Perl". :) >> > Excellent argument, poor choice of example code *cough*. Second reply, after reflection. Okay, I think you are saying the example isn't very good because Ruby has the same ambiguity. Perhaps Matz didn't want to leave C++ converts without any familiar landmarks? -- Paul Lutus http://www.arachnoid.com