Skip to content
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

scan-left, scan-right: position argument, array functions #982

Open
michaelhkay opened this issue Jan 31, 2024 · 4 comments · May be fixed by #1296
Open

scan-left, scan-right: position argument, array functions #982

michaelhkay opened this issue Jan 31, 2024 · 4 comments · May be fixed by #1296
Labels
PRG-easy Categorized as "easy" at the Prague f2f, 2024 XQFO An issue related to Functions and Operators

Comments

@michaelhkay
Copy link
Contributor

michaelhkay commented Jan 31, 2024

We have added an optional position argument to nearly all callback functions that are invoked once for each item in a sequence. This argument is omitted from the new scan-left and scan-right functions. It should be added for consistency.

One of the proposed use cases for scan-left and scan-right is for debugging calls on fold-left and fold-right. This use case requires that the callback functions in the two cases are compatible.

Background note: the optional position argument is modelled on Javascript, where it is permitted in all the common higher-order functions such as filter, forEach, reduce and reduceRight (which are the Javascript equivalent of fold-left and fold-right). Javascript doesn't appear to offer an equivalent of scan-left and scan-right.

@ChristianGruen ChristianGruen added XQFO An issue related to Functions and Operators Enhancement A change or improvement to an existing feature labels Jan 31, 2024
@dnovatchev
Copy link
Contributor

Although this seems not too-meaningful for folds and scans (and I have the expressed opinion by @adamretter saying "I agree that fn:fold-left and fn:fold-right functions should not have index arguments.) ", I would not object to this if the additional argument is in a separate overload. Thus, if we have two separate overloads, the first one as is now - with the $action argument being a function of 2 arguments, and the second one with the $action argument being a function of 3 arguments.

Combining these two overloads into a single one is not only formally problematic, but also requires unnecessary mental gymnastics for the reader to clearly understand the specification, when this issue would completely be non-existent if we had two separate overloads.

@michaelhkay
Copy link
Contributor Author

Consistency is very hard to achieve in a language designed by committee, but it's not acceptable to have two different functions do the same thing in different ways just because they were put forward by different people. If we make a change to the way this is done, it needs to be done across the board, not just in one function.

@dnovatchev
Copy link
Contributor

Consistency is very hard to achieve in a language designed by committee, but it's not acceptable to have two different functions do the same thing in different ways just because they were put forward by different people. If we make a change to the way this is done, it needs to be done across the board, not just in one function.

Microsoft is a good example of producing a language that is not designed by committee, and yet they decided not to add an overload where the $action argument is a function that has the position in the collection as an added new argument.

Why Microsoft didn't do this in the specification of Enumerable.Aggregate method ?

Not because they missed something (we are at ver. 8 of .NET, and LINQ was introduced almost 20 years ago - in ver.3, so they have had plenty of time to notice and correct any omissions), but because they decided (as both @adamretter and I concur) that this has little meaning, if any at all.

@ChristianGruen ChristianGruen added the Propose for V4.0 The WG should consider this item critical to 4.0 label Feb 2, 2024
@dnovatchev dnovatchev removed the Propose for V4.0 The WG should consider this item critical to 4.0 label Feb 10, 2024
@dnovatchev dnovatchev removed the Enhancement A change or improvement to an existing feature label Feb 27, 2024
@ChristianGruen ChristianGruen added the Propose for V4.0 The WG should consider this item critical to 4.0 label Mar 26, 2024
@ndw ndw added PRG-easy Categorized as "easy" at the Prague f2f, 2024 PRG-required Categorized as "required for 4.0" at the Prague f2f, 2024 labels Jun 4, 2024
@ChristianGruen
Copy link
Contributor

In addition, we should add array:scan-left and array:scan-right. My suggestion would be to be less paternalistic and align the result types of fn:scan-(left|right) with fn:for-each, and to use the array functions for structured results. Of course, nothing prevents a user from creating structured results with fn:scan-(left|right) as well.

@ChristianGruen ChristianGruen changed the title Add position argument to scan-left and scan-right scan-left, scan-right: position argument, array functions Jun 6, 2024
@dnovatchev dnovatchev removed Propose for V4.0 The WG should consider this item critical to 4.0 PRG-required Categorized as "required for 4.0" at the Prague f2f, 2024 labels Jun 6, 2024
@michaelhkay michaelhkay linked a pull request Jun 23, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PRG-easy Categorized as "easy" at the Prague f2f, 2024 XQFO An issue related to Functions and Operators
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants