On 2/26/07, Dan Weston <[EMAIL PROTECTED]> wrote:
P. R. Stanley wrote:

> In C, for example, iteration could be implemented using the if construct
> with the dreaded goto command. So, strictly speaking, the while loop
> could be classed as syntax sugar. Yet, the while loop is a
> well-recognized construct in its own right.
> I hope you can see what I'm driving at.

Syntactic sugar is fully desugared at compile time. A while loop with
constant limits *could* be considered syntactic sugar if the compiler
can statically unroll the loop. Variable limits are definitely beyond
this definition, since they can only be evaluated at runtime.


I think what P.R. meant is that while loops in C can be desugared like this:

while(condition) {
 stuff
}
more_stuff

=>

loop:
 if(!condition)
    goto exit;
 stuff
 goto loop;
exit:
 more_stuff

No static unrolling of the loop happens. So in the sense of "syntactic
sugar" that means "a construct that can be defined in terms of other
language constructs", while is syntactic sugar in C.

Not sure what the original point was, though.

Cheers,
Kirsten

--
Kirsten Chevalier* [EMAIL PROTECTED] *Often in error, never in doubt
"Are you aware that rushing toward a goal is a sublimated death wish? It's no
coincidence we call them 'deadlines'." -- Tom Robbins
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to