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; 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.
However C's for-loop genuinely *IS* primitve.
Yet has higher expressiveness. We disagree what "primitive" means;
so it's hard to continue the discussion below since we're speaking
different languages, obviously.
I cannot program non-trivial or complex loops with Pascal or BASIC,
they are too restricted (to just one application way), they're too
primitive. We've provided many examples in this thread.
While "C" based its loop on primitive building blocks (statements
and conditions) you can use in the loop all sorts of concrete "C"
building blocks, including an assignments for the initializations
and an increment for the next iteration; as support of a special
case for the simple, primitive forms as found in other languages.
[...]
Suppose that C had both its primitive loop, and one like Basic's (or
like Awk's); would that be better? If so, why?
The BASIC dialects I know of supported only one type of loop; the
simple arithmetic loop. As opposed to Pascal's loop it's possible
to iterate over real arithmetic ranges, though, but that's it.
Awk decided to support two types of loops. The 'in' loop is the
"normal" loop (the arithmetic loop is, for reasons obvious to me,
the extension); since Awk supports only one data structure, namely
associative arrays (and no indexed arrays) you need some iteration
construct that iterates over the keys; "for (key in array)". The
arithmetic loop is there because functions like 'split()' create
associative entries with keys "1", "2", etc. (not numeric indices
1, 2, etc.). But with the implicit type coercion an arithmetic
'for' loop numbers get converted to strings used as key in Awk's
associative arrays. Awk is a higher level language than "C" is,
its array type is more powerful than the indexed arrays we find
in "C". So there's different requirements.
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. 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.
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.
Read what I explained above to get some clue about Awk.
[...]
Effectively you are arguing for there to be no higher level languages,
because anyone who wants them must also be incapable of understanding
and using what there is.
(I don't understand what you write here. But what you think is anyway
meaningless here since I already _wrote_ what I _intended_ to say and
that needs no (mis-)interpretation of you.)
[...]
I've written many 10s of 1000s of lines of assembly. But I prefer HLL
code, and HLL code which has some must-have fundamentals. Like a fucking
loop that works.
Fine. I can completely understand your desire of using HLLs. That's
what I like as well, HLLs. - Just give up considering "C" a HLL and
stop asking about pointless abstractions in "C". - As opposed to Awk
you don't have associative arrays that make an 'in' loop necessary,
and you can do anything with "C" loops that is necessary, much more
than with some other languages' (of higher level or not) restricted
loops. You may not make use of "C"'s loop flexibility, you may not
need it for your application cases, yet it's something that's very
useful (as shown in many examples). If you can't handle "C" loops
don't use that language. Why are you here, in CLC; just to complain?
Janis