On 22 March 2010 18:39, Jonathan S. Shapiro <[email protected]> wrote:
> Here's a mundane issue - but one that I seem to be stuck on. I'm
> hoping that someone will know about a solution that I am not seeing.
>
> Converting to new syntax mostly isn't that hard. It's an adventure in
> shift/reduce errors, to be sure, but that's not such a big deal. The
> hidden challenge is turning out to be iterator syntax. I'm hoping
> somebody will have a suggestion that I have not seen.
>
> In traditional "systems" languages, we have three types of loops:
>
>  while(expr) { ... };
>  do {...} while(expr);
>  for(pre; test; incr) {...};   // syntactically rewritable to while form
>
> This style relies on the fact that the languages are imperative. If
> these languages were pure, then of course the predicate expression
> results would not change.
>
> There are two sub-cases:
>
>  - We know how many iterations before we enter the loop. This is true
> with FORALL
>  - The loop condition computation result is altered by the loop body. This is
>    the usual case in systems codes.
>
> In pure languages, we tend to have loop syntaxes that turn into
> labeled-continue mechanisms. LET LOOP is a good example. After a time,
> these seem normal to LISP programmers, but remain puzzling in the eyes
> of systems programmers.
>
> Given that BitC wants to straddle the line between imperative and
> functional styles, I'm struggling with finding a comfortable looping
> syntax. If I can't find one, I'll probably just bite the bullet and
> support distinct imperative and functional syntaxes, but it would be
> nice not to do that.
>
> Suggestions? Other languages to look at?
>
>

I would say that foreach cycle and while cycle are fundamentally
different and while you can make them use the same keyword and similar
syntax it does not change that.

The foreach cycle operates over the input data and exactly over the
input data and so long as the data ends and the body does not do
something nasty the cycle also ends.

The while cycle is in its nature imperative, would probably need an
infinite if-else branching to represent in a pure way in the general
case and the very simple while(1) is in itself infinite.

The fact that in C there is for() and while() and they are in fact
equivalent (for being a syntactic sugar making it easier to see/not
forget the loop upkeep) is a different story.

Thanks

Michal

_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to