-
-
Notifications
You must be signed in to change notification settings - Fork 555
list-ops: division operator is ambiguous #1467
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've always read this pretty much in the C-sense… We get 2 integers in, so we get an integer out. I never thought of reading it the erlang or elixir way… As long as we get numbers in, we get a float out. If though we try it the erlang ( We also might meet some esotherical language, that does not even allow for division directly. In my opinion we should make the tests self contained: {
"description": "direction dependent function applied to non-empty list",
"property": "foldl",
"input": {
"list": [2, 5],
"initial": [],
"function": "(x, y) -> cons(x, y)"
},
"expected": [5, 2]
},
{
"description": "direction dependent function applied to non-empty list",
"property": "foldr",
"input": {
"list": [2, 5],
"initial": [],
"function": "(x, y) -> cons(x, y)"
},
"expected": [2, 5]
} Where |
Python appears to have an explicit integer-division operator as well,
That's basically what I said, finding a way to express integer division that is understood easily among all languages is probably impossible. Subtraction would be a better choice, since it is also direction-dependent in the sense that
I'm not sure if |
The first that comes to my mind is C… If one argument is float-y, the result is as well. |
Yes, but that's not the point. The test cases provide only integers, never floats. The result, however, is determined by how a language uses the division operator, ie if it does an integer or float division and under which circumstances. So this is a rather language dependent part. With |
Yes, I think I do. |
:) Anyway, I think making the tests self-contained the way you suggested is a good (better) way, too. What |
#1746 makes unambiguous:
|
problem-specifications/exercises/list-ops/canonical-data.json
Lines 161 to 170 in 69395c4
problem-specifications/exercises/list-ops/canonical-data.json
Lines 196 to 205 in 69395c4
The two cases instruct the test implementation to apply the division operator
/
to the two arguments of the function used for folding.This operator is ambiguous, depending on language and circumstances. There are languages which always do floating-point division with
/
and have a separate operator for integer division (egdiv
inErlang
), others do integer division if both operands are integers and float division only if at least one operand is a float, etc.The current test cases in question assume integer division, but this is not obvious, only if you (as a human) read the test arguments and expected outcome carefully. For a test generator on the other hand, it is quite difficult.
As finding a language-agnostic way to explicitly specify integer division would pose rather difficult, I suggest to alter the test cases to use another direction-dependent but unambiguous operation instead, like
-
.The text was updated successfully, but these errors were encountered: