On Tue, Mar 30, 2010 at 7:02 AM, Michal Suchanek <[email protected]> wrote:
>
> You mean the C
>
> while() {}
> {} while();
>
> loops?

Actually, I meant "while() {}" and "do {} while ()", but yes. :-)

> I would expect that for(;;) would not be needed when constructs like
> foreach or map are available so you can just have a syntax which
> allows the condition to be at the beginning or the end like

for(;;) isn't a big concern. It's mere syntactic sugar on "do {} while
()". If adding this syntactic sugar helps programmers migrate, it's
probably useful.

The mildly subtle problem is the result type of the loop construct.
Because the "do {} while()" form executes at least once, we can
declare that the value of the loop is the value of the last statement
executed within the body (I'm ignoring explicit "break" for this
discussion, but we can extend to that easily).

Unfortunately, the "while() {}" form may *not* execute even once, and
so we cannot determine the type of the value. This is like the
difference between

  if () then e1 else e2
  if () then e1

In BitC, we chose to resolve this by deciding that a missing else
clause was treated as "else Unit". That is: a one-legged if must
return unit. I suppose that we could do the same thing with the
"while() {}" form. Would that strike people as weird?

I'm not concerned about keywords here. What I'm really concerned about
is expressions vs. statements.
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to