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
Effect of atomization on array:index-of() #1096
Comments
I agree, this may be confusing. On the other hand, considering that My (and I think Dimitre’s) initial suggestion was to use |
Yes, I think using deep-equal would give fewer surprises. But then you might as well use |
That’s certainly true. I would probably do it, but the idea was to offer a function for people who don’t use higher-order functions (which will still be the majority). |
In what way is that confusing? I think the key thing with Another solution might be to atomize the members of the supplied array, but not the array itself. Change the definition to
With this definition the following expressions will all return 2:
|
Note also, the rather cumbersome
could be replaced by
if we had such a thing. We have I proposed these three functions in PR #222 in response to issue #94 and issue #96, and the only reason I didn't propose the The requirement for Or perhaps we should instead have a more powerful |
In a way that atomization of arrays (although powerful) is still largely unknown to users (at least the ones I have come across). But from a technical point of view it’s consistent.
Looks good ( |
Maybe just |
In PR #1100 I have proposed a new fn:equal() function, and I propose we redefine array:index-of to use it. Specifically
|
Sounds good. Following your suggestion to atomize the members of the supplied array, it should probably be |
Well, I was proposing here to NOT atomize, because I think that's clearer when dealing with arrays. I was also proposing to use atomic-equal() by default, which is context free and therefore doesn't use a collation; if they want a collation, they can supply a callback that uses one. But we could change it to |
Makes sense. Regarding collations, I’m not really fond of them, I just noticed that the signature would differ from |
Yes, definitely. and also:
Recently I needed a function to compare two arrays for "less than" and couldn't find one. I ended up using |
What is the expected result of the expression:
array:index-of( [[1,2], [3,4]], [3,4] )
It seems that the second argument is atomised (because its declared type is atomic), but the first argument is not.
So both members of the array have count=1, whereas $search has count=2, so nothing matches, so the result is ().
Now, what if we write:
array:index-of( [[1,2], (3,4)], [3,4] )
This time it seems that the second member of the array matches, so the result is 2.
This doesn't feel right. One solution would be to say that each member of the array is itself atomised. But that seems to lead to other surprises with other examples of nested arrays.
An alternative would be to atomize neither argument (which would mean changing the function signature). But then we would need to use a different comparison operation.
We seem to be back where we started -- I was unhappy about introducing this function because of the difficulty of defining a good comparison operation for it to use.
The text was updated successfully, but these errors were encountered: