-
Notifications
You must be signed in to change notification settings - Fork 15
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
HOF Sequence Functions with Positional Arguments #181
Comments
@ChristianGruen I am really sorry, but I read and re-read this multiple times and I really cannot understand what is being proposed here. All of the listed standard functions ( I apologize for being that dumb :( :( :( Now that I am reading it again, I begin to understand the meaning: it is not to add a function parameter to certain standard functions, but the proposal may be made easier to understand by formulating it as: "Extend the types of the functions that are themselves parameters to certain standard functions, by adding to their signature one more parameter, which is the index of the item that is also passed as an argument to this function" Or something similar |
@dnovatchev Thanks for your reply. It’s definitely not you who’s dumb; instead, I should invest more time on phrasing things. Your formulation sounds fine, which is why I adopted it directly in my comment. In addition, I added some comments to the example queries. Again, my idea is something that has already been realized in other programming languages. The most prominent example may be Do you think the extension would be helpful? |
Yes, this is what I have been intending. The change is hinted at in §4.4.4 of the draft XPath specification, where I wrote:
Note also that Javascript filter callbacks work this way, so the concept will be familiar to many users. |
@michaelhkay Great; thanks. |
Yes, and this is also one of the overloads of .NET LINQ I myself proposed such general amendment at one of our previous meetings (https://qt4cg.org/meeting/minutes/2022/09-20.html when discussing We need to add this new argument to all parameter-function-values -- of all current and projected new standard functions that accept as input a sequence or an array and pass to that parameter-supplied function just the item (member), but not also the index. |
Can't we eliminate this problem altogether by having these signatures ?
and
|
We obviously can't require the caller of |
Doubtless a very useful extension! As Michael Kay so succinctly said: "makes it easier to design versatile and extensible higher-order functions". To add a (pseudo?) theoretical note: the information content of the function input is extended from the "item" to the "item as a member of the sequence", which gives it a sequence-scoped identity. Any aspect of the relationship between the information content of the item and of the sequence becomes accessible. |
The obvious and hanging suggestion that we need to do the same to all array:functions that are the counterparts of the standard functions defined on sequences. With the risk of missing something, these are:
|
I’m summarizing the functions for which positional arguments would be beneficial:
In addition, it could be added to: |
Add fn:sort. People use position() in xsl:sort, it can provide a neat way of arranging data in tables. Probably map:build() too. |
Here is an observation and proposal following from it: Within a for - expression in XPath we currently don't have access to the index(es) of the bound variable(s). In the spirit of the current proposal, I also propose to have such facility within a for - expression* . For example, we could have an expression like this: for $x in (1, 3, 5, 7, 9, 11),
$y in (1, 3, 5, 7, 9, 11)
return
if(index($x) le index($y)) then [$x, $y]
else () Which produces all pairs of items in which the 1st item in the pair is from the first sequence ( [1,1]
[1,3]
[1,5]
[1,7]
[1,9]
[1,11]
[3,3]
[3,5]
[3,7]
[3,9]
[3,11]
[5,5]
[5,7]
[5,9]
[5,11]
[7,7]
[7,9]
[7,11]
[9,9]
[9,11]
[11,11] Note: Probably we need just to expand the XPath syntax with the for $x at $ind-x in (1, 3, 5, 7, 9, 11),
$y at $ind-y in (1, 3, 5, 7, 9, 11)
return
if($ind-x le $ind-y) then [$x, $y]
else () Your thoughts appreciated. |
@dnovatchev Would you mind creating a separate issue for the proposal? I immediately thought of the |
Closed in favor of #516. |
Sorry about the duplication. |
Motivated by @michaelhkay’s question in #80 (comment), I wondered if we should
add optional positional arguments to built-in sequence functions that take higher-order function arguments(thanks, Dimitre:) extend the types of the functions that are themselves parameters to certain standard functions, by adding to their signature one more parameter, which is the index of the item that is also passed as an argument to this function.Some examples:
Edit: I was wrong with my claim that the filter function could be used to replace
index-where
, and I have modified the example.The text was updated successfully, but these errors were encountered: