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
{{ message }}
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.
Wrong behavior
Try to iterate over a range of bytes with a for-loop:
for (bin0.byte..3.byte) {
print(b);
}
Try it!
Trying to run this on try.ceylon-lang.org gives this error:
undefined — Runtime error:
undefined — --- TypeError: $1i.compare is not a function
Script ended with no output
Expected behavior
Running this code should print
0
1
2
3
Analysis
From the error message, it looks like some part of the compiler is trying to convert this into a classic increment-comparison loop. But bytes in Ceylon have no total ordering, and thus also no comparison operators or compare functions.
The text was updated successfully, but these errors were encountered:
The .. operator is syntax sugar for ceylon.language::span, which only requires that its arguments be of a type satisfying Enumerable, and (per its docs)
An Enumerable type is characterized by each element having well-defined offset and neighbour() functions.
Bytes don't have a total ordering in Ceylon because they aren't specifically signed or unsigned, and offset and neighbour are defined in terms of modular arithmetic, wrapping around.
I tried the code in the OP above on the JVM, and it gives the results shown under "Expected behavior" above. I also compiled it to JS using ceylon compile-js, and the code above compiled to
Ah, so the problem is not on the loop condition, but already when trying to figure out whether to do an upwards or downwards iteration, which doesn't apply for a recursive Enumerable type like Byte. I guess that first comparison should call $3.offset($2) < 0?
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Wrong behavior
Try to iterate over a range of bytes with a for-loop:
Try it!
Trying to run this on try.ceylon-lang.org gives this error:
Expected behavior
Running this code should print
Analysis
From the error message, it looks like some part of the compiler is trying to convert this into a classic increment-comparison loop. But bytes in Ceylon have no total ordering, and thus also no comparison operators or
compare
functions.The text was updated successfully, but these errors were encountered: