Liste des Groupes | Revenir à cl c |
On 16/04/2025 22:43, Kaz Kylheku wrote:On 2025-04-16, bart <bc@freeuk.com> wrote:>On 16/04/2025 06:35, Janis Papanagnou wrote:On 15.04.2025 22:46, bart wrote:>On 15/04/2025 20:07, Scott Lurndal wrote:[...]>
Real for loops _are_ a three-way construct.
>
[...]
Any step other than 1 is unusual. [...]Nonsense. Arithmetic loop steps other than one are noting unusual>
and been supported by programming languages (and also been used)
since decades in programming.
So what are you claiming, that the majority of loops in any given
program will have steps other than +1 or -1?
Hey Bart, how would you handle a loop like
do x = m to n ...
where m and n are not known until run time, and may be the
extreme values of the type? Like C's INT_MIN and INT_MAX, respectively,
where x is of type int.
Because in this loop, x takes on every possible value of the type,
we cannot have a loop guard which prevents entry of the loop body
based on solely the value of x.
I'm not exactly sure what you are asking. Is it a loop like this, here
in my language:
>
int n:=0
>
for i in i32.bounds do # ie. i32.min .. i32.max
++n
od
>
println n
>
This works fine; after a second or so it displays 4294967296.
>
However, this languages evaluates using 64 bits. Perhaps this loop may
demonstrate the issues better:
>
for i in i64.bounds do
>
However, I would estimate it would take 190 years to finish.
I assume you're thinking of C which uses i32 and where comparisons near
the extreme values of the type are problemetical. Or this line in my
language:
>
for i in i64.max-10 .. i64.max do println i
which doesn't stop (u64 is OK however).
That doesn't worry me too much,
I can just add a Note to the language spec warning of UB when a for-loop
bound is at the limits of the type.
Where all sorts of other stuff can
happen because of how values wrap.
Then we can do>
for (int i = INT_MIN; : i < INT_MAX; i++)
After the last iteration, i is INT_MAX, and so the test fails.
The loop terminates without performing i++.
You're trying too hard. I don't think the language needs to bother
providing solutions, it just needs to specify the limitations.
Les messages affichés proviennent d'usenet.