[Nickle] Scope for condition of do while
Bart Massey
bart at po8.org
Fri Feb 1 19:56:17 PST 2008
In message <871w7wupqa.wl%cworth at cworth.org> you wrote:
> Should this be a legitimate thing to do?
>
> do {
> putchar (int c = getc (socket));
> } while (c != '.');
>
> That is, should the while condition share scope with the block above
> even though it's syntactically outside?
>
> Keith whipped up a special-case implementation of this, but he's
> definitely not sure that it's not a horrible idea. He's planning to
> cogitate a bit more, so I'm just sending this to remind him to type
> his thoughts at some point, and also to solicit any other thoughts
> others might have.
>
> -Carl
Note that if you replace '.' with EOF in your example, it
breaks it. Normally one would have to write something like
while (true) {
int c = getc(socket);
if (c != '.')
break;
putchar(c);
}
On the other hand, our try scoping hack set the precedent
that it's OK to continue the scope a ways after the block.
try {
int c = getc(socket);
} catch io_error(e,s,f) {}
if (c != '.')
putchar(c);
The above is legal. Maybe do should be special too.
Bart
More information about the Nickle
mailing list