On 19/04/2025 12:32, Janis Papanagnou wrote:
On 19.04.2025 12:26, bart wrote:
On 19/04/2025 07:27, Janis Papanagnou wrote:
On 19.04.2025 00:27, bart wrote:
>
So, yes, I think that is problematic, and the fault is with the
language. This stuff isn't not hard to get right; even BASIC manages to
FOR-loops properly.
>
As so often explained to you, BASIC has a most primitive loop.[*]
>
As has been so often pointed out, the vast majority of iterating loops
can be accommodated by 'for i = a to b'. So in that case it is not
primitive.
Why is that not primitive? It is about the most restricted loop
concept one can think of;
With the optional step (which is so uncommonly used that I'd forgotten it even had it), it handles the vast majority of loops where you want a variable to iterate over a range.
That includes everything that Algol68 loops do that use 'for'. ('While' is an early exit that can achieved with if/goto, but is anyway a feature of 'for' that is uncommon.)
I'm doing hard to imagine a yet more
primitive one. All other loops pointed out that far (Algol 68,
Simula, "C") allow more complex (less primitive) loop constructs.
C, really?
I don't understand why you're happy using a crippled looping mechanism, that is a PITA to use for the majority of iterating loops, just so you have that flexibility for the whacky loops that are in the minority, most of which can be trivially expressed with 'while'.
>
However C's for-loop genuinely *IS* primitve.
Yet has higher expressiveness.
So has 'if' and 'goto'. (I think we've been here before!)
We disagree what "primitive" means;
so it's hard to continue the discussion below since we're speaking
different languages, obviously.
I'll tell you a secret: a few years ago, I also added a C-style 'for' statement to my language. So it had two kinds of 'for' that looked like this:
for i in a..b do # also for i[:=a] to b do
cfor A, B, C do # A B C are arbitrary expressions
This was because I'd got fed up with people telling me all these wonderful things that C's for could do, that I couldn't. So now I could do the same!
But it eventually got dropped as /it was never used/. Why would it? I already head the dedicated 'for' for iterations. To express the above loop using 'cfor' meant writing:
cfor i := a, i <= b, ++ i do
Four extra lots of info (2nd i, <=, ++, 3rd i) , which I needed to get just right. No thanks.
If you were me, would you have instead have got rid of the dedicated 'for', and kept only 'cfor'? Be honest!
Since that is exactly what you have been saying about C's 'for'; you don't /want/ a better 'for' in C, even if it was in addition to the current 'for': 'there is nothing wrong with latter, and anyone who can't hack it should give up programming'.
I understand that the "C" language designers decided to not provide
some additional form of loops; that's IMO a sensible decision given
what low-level language "C" is.
Mine is too. The original version was even lower level and simpler and smaller, but it still had PRINT and FOR.
To define its loops in a flexible
form by building blocks as we know them from other places in the
"C" language makes perfectly sense.
I don't need a second loop in "C". I know it would help you to not
make the errors you seem to regularly make as you say.
Lots of people do.
>
In fact, WHY does Awk have that other kind of loop? Since the primitive
form can express it just as well.
No. You have a complete misconception about that. In all respects.
Really? So why does this work:
split ("one two three four five", table)
for (i=1; i<=5; i++)
print i, table[i]
I thought you said Awk didn't support indexed arrays? (Wrap in 'BEGIN {...}' for a complete program.)
don't use that language. Why are you here, in CLC; just to complain?
I'm here to understand why people are deifying C and its crude for-loop by arguing that black is white:
do i = 1,10 # 'primitive'
for(i=1; i<=10; ++i) # 'advanced'
But then at the same some are saying that:
'for' i 'from' 1 'to' 10 'do'
from Algol68 is advanced (because you can stick 'while' in there?).
It's a fascinating. I guess the answers are more psychological than otherwise.