It was thus said that the Great 'Martin Eden' via lua-l once stated:
> Side thought: most cases are "for 1, f()"
>
> What if we have "repeat <N> do ... end" construction. Will it make code
> better?
Some musings while dinner is cooking.
I came across a language decades ago (in a magazine article, so no direct
experience) that used '!' as a looping mechanism, and was used to replace
for, while, do while and several other variations. I'll use a slight
variation to make the examples cleaner, with the following conventions:
i - integer scalar
x - integer scalar
f - boolean scalar
a - array of values
A loop repeated 10 times:
{!10 <code> !}
There is no control varible to mangle. If you wanted a variable number of
iterations:
{!x <code> !}
as long as x >= 1, it would loop x times. Again, no control variable to
mangle---x could change in the code block, but its use as a limit was done.
If you wanted a control variable:
{!i=x <code> !}
Each time <code> was executed, i would be successive values. The language I
read about didn't mention if i was read-only (I did read about this in the
early 80s, times were different then) but I suspect today it would be
read-only. Then there is:
{!x=a <code> !}
where x is successive values from the a array---no index value though. If
you wanted an index (and the original language didn't include this), maybe:
{!i,x=a <code> !}
But so far, all the examples have been replacing a for-loop. A while-loop
would look like:
{!x<50 <code> !}
One can do a repeat-until loop as:
{! <code> x>50!}
and of course, both can be used:
{!x<50 <code> f!}
And even a for-loop start with a until clause at the end:
{!100 <code> f!}
for a loop that executes up to 100 times, or until f is true, whatever
happens first.
I've always liked this idea for looping [1], but never got around to
implementing a language with it, nor have I ever seen an implemetation of
the language that inspired this idea. I know what I described will probably
never show up in Lua, but it was fun to muse about it.
-spc
[1] The language itself had no key words in it. All syntatical
constructs are done via symbols; "!" for loops or "?" for ifs, that
type of thing. Fun to think about.