You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 415 Reporter: administrator Status: closed Resolution: fixed Priority: normal Severity: minor Category: ~DO NOT USE (was: OCaml general) Parent of:#5999
Bug description
Full_Name: Cuihtlauac ALVARADO
Version: Objective Caml version 3.01
OS: Red Hat Linux 6.2, Kernel 2.2.19-6.2.7
Submission from: machine107.rd.francetelecom.fr (193.49.124.107)
This loops :
for i = 0 to max_int do
if i mod (max_int / 10) = 0 then Printf.printf "%i\n" i;
flush stdout
done;;
While that does not
let rec f i =
if i <> max_int then begin
if i mod (max_int / 10) = 0 then Printf.printf "%i\n" i;
flush stdout;
f (i + 1)
end in (f 0)
Am I missing something ?
The text was updated successfully, but these errors were encountered:
for i = 0 to max_int do
if i mod (max_int / 10) = 0 then Printf.printf "%i\n" i;
flush stdout
done;;
While that does not
let rec f i =
if i <> max_int then begin
if i mod (max_int / 10) = 0 then Printf.printf "%i\n" i;
flush stdout;
f (i + 1)
end in (f 0)
Am I missing something ?
That's a known issue -- a rather amusing one, actually. Basically, the
"for" loop in the first example is compiled into:
let i = ref 0 in
while (!i <= max_int) do
...
i := !i + 1
done
and the test !i <= max_int is always true by definition of max_int.
Hence the infinite loop.
Notice that your second example is not equivalent to the first: it
iterates up to max_int - 1, not up to max_int, just like
"for i = 0 to max_int - 1 do done". (And the latter terminates
without problems.)
If you try to rewrite your second example so that it iterates up to
max_int included and stop, you might realize the difficulty of
correctly compiling "for" loops with max_int as upper bound...
I agree something should be done about this, but it's not completely
trivial to fix and doesn't seem too urgent.
Original bug ID: 415
Reporter: administrator
Status: closed
Resolution: fixed
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)
Parent of: #5999
Bug description
Full_Name: Cuihtlauac ALVARADO
Version: Objective Caml version 3.01
OS: Red Hat Linux 6.2, Kernel 2.2.19-6.2.7
Submission from: machine107.rd.francetelecom.fr (193.49.124.107)
This loops :
for i = 0 to max_int do
if i mod (max_int / 10) = 0 then Printf.printf "%i\n" i;
flush stdout
done;;
While that does not
let rec f i =
if i <> max_int then begin
if i mod (max_int / 10) = 0 then Printf.printf "%i\n" i;
flush stdout;
f (i + 1)
end in (f 0)
Am I missing something ?
The text was updated successfully, but these errors were encountered: