-
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
517: fn:chain #734
517: fn:chain #734
Conversation
As I closed PR 733, here is the useful comment from @michaelhkay that I am transferring here (from there): First of all, thank you, Michael for the useful comments!
Done
Fixed in the latest to be pushed.
I agree with this thinking. However, this is just one possible implementation and it is a "black box" to the user. This means that nowhere are we encouraging anyone to think that the existing rules are not enforced. Any implementation could be done in any language (not XPath at all) thus we are not prescribing to the implementors exactly what coding techniques to use - just that their results must be identical to the results produced by this oracle.
Yes, but this significantly reduces the power and usefulness of the function. Please, note that nobody is prohibiting the user to use functions that always need a single argument, and indeed many users will do so. However, when this is necessary, fn:chain provides the power to chain together functions that can get their arguments from an array (or a sequence). We already have this feature in the standard XPath function fn:apply, which gets all needed function arguments from a user-provided array, thus this is not something new, and definitely not a violation of the established Xpath practices. This function provides capabilities similar to those of transducers, first proposed by Rich Hickey in Closure. A transducer in a chain of transducers doesn't depend on (or even know) the type of its input or the type of its output.
This would be a nice new function to have, and it will be useful in other cases. Here it is suggested that the "singularization" is performed inside the black-box implementation, so that the result is most concise, short, readable, convenient and meaningful to the user.
Done in the latest to be pushed.
Absolutely! Your help will be appreciated!
Done in the latest to be pushed. Once again, thank you! |
Thanks for your efforts. As you may have seen in the GitHub diff view, the files still have lots of differences. The new files seems to use a different indentation with tabs instead of spaces. Which text editor do you use? |
Thanks. So the outstanding question is how to handle arity>1 functions: I think we need to discuss this. The current logic (which I have inverted for clarity):
So the three cases are:
If we made this change I think the rules would be much easier to state and to understand:
|
dnovatchev ***@***.***> writes:
Added fn:chain.
Took much effort to ensure Unix-style line-endings are used.
We should configure Git to fix that for you. “On my list.”
Be seeing you,
norm
…--
Norm Tovey-Walsh ***@***.***>
https://norm.tovey-walsh.com/
It is seldom that any liberty is lost all at once.--David Hume
|
Thanks, Norm (related: #698) |
Wow Norm, thank you so much! 💯 |
Initially (unaware of this problem) I used the VS XML Editor. Then, in order to fix the problem, I used NotePad++. It has built-in command for converting CR+LF to LF . |
This is the "sauce" of the function. This is what makes the function so powerful. So far we have been filling the FO with a multitude of convenience functions, that are just synonyms for expressions that the user could write easily. Let's have at least a few functions that provide greater power.
We are not guessing - the specification of the function (Note 3) tells directly and precisely how the current result is processed in this case.
I would rather keep the function as it is, no one forbids the user to use I think we could add a final note, telling the reader, that it is recommended to start initially using the function just as So, the two bullets will be almost the same as the above:
|
Good to know, thanks. Could you try to commit a version with the original indentation (space characters instead of tabs)? |
I did, but there are still 14K + differences |
@ndw Can DeltaXML be configured to ignore any blanks<-->tab or CRLF <--> LF differences? Or even whetespace-only differences? |
I advise you to take the original files, add your edits without modifying the indentation of the overall file, and push these files into this pull request. It's not only about DeltaXML, it's also about not losing track of the actual changes in the git history, and to reduce conflicts with other pull requests. |
Finally done successfully! 😄 Thanks for your support! |
+1 for the solution with arity-1 functions. For functions with a higher arity, people could be confused about the missing symmetry. This query would work… let $input := array { 2 to 3 }
let $fn := fn { . > 2 }
return fn:chain(($input, $fn), array:filter#2) …but this one wouldn’t: let $input := (2 to 3)
let $fn := fn { . > 2 }
return fn:chain(($input, $fn), filter#2) And we should need to define what is going to happen if arity-0 functions are supplied. |
Thanks for this comment.
There is nothing confusing here. Note 3 specifically says:
I absolutely agree that the flat sequence is a bad and misleading data-structure, but this is not a fault of fn:chain ...
This follows from the rules and notes. A function with Similarly, a function in the chain that produces nothing() must be followed by a zero-arity function, or must be the last function in the chain. Do you want me to include a new note explaining this? |
A feature can be confusing even if its behavior is clearly defined in the spec. Symmetry, orthogonality and simplicity are well-proven design principles, and I believe the function would be more intuitive and easier to understand if we restricted it to arity-1 functions.
I agree, too. It’s precisely the reason why I think we should be strict, and not include built-in functions that motivate and support the usage of flawed data structures. I’ve checked all your examples, and I noticed that most of them only use arity-1 functions anyway. Some others use $product3 := function($x, $y, $z) { $x * $y * $z }
→ $product := fold-left($n, 1, op('*'))
op('*')
→ $product
contains#2
→ fn($a) { contains($a[1], $a[2]) }
→ fn { contains(head(.), tail(.)) } The focus function in the last example (
Do you have a working example? The following one results in an exception, at least with the included XPath code: |
I have learnt over time that confusingness is in the eye of the beholder. If someone says it is confusing, then by definition, it is. |
Thanks for catching this, @ChristianGruen . I fixed this and added this as an example. Please, do have a look. As for:
Users have been accustomed for years to the fact that the standard XPath 3.1 function fn:apply requires that the arguments to the function call must be passed in an array. And this is what fn:chain is doing. Nothing new has been done, and speaking of confusing features, we have such outstanding examples, as the XML namespaces, which, compared to fn:apply are like mountains compared to a grain of sand. |
The existence of confusing features shouldn’t be a motivation to add more of them. But I understand that it seems important to you to keep the current proposal unchanged. |
It is not that. It is simply the fact that the standard fn:apply has been there for everyone for 7 years now, so people know that this standard function (fn:apply) requires that the intended arguments for a function call must be packed into an array - and this is exactly what fn:chain does. |
I can add examples such as Volume, Area, TriangleArea, etc. of well-known formulas that would definitely be degraded into unreadable mess if we pass all parameters not separately, but as items in a single sequence. The beautiful Heron's formula for the area of triangle would have now to use Even more ugly would be the formula for the roots of a quadratic equation. Reminds me of that old joke about the man who agreed to have a suit with many unnatural limitations: “Good heavens. Look at that poor crippled fellow,” the first doctor said to the second. “Yeah but doesn’t that suit fit great?” |
I have added the 2 error examples as recommended by @Arithmeticus . Please, have a look. |
Looks ok, except that the custom in the specs, when providing an example that raises an error, is to say "Raises error CODE." or "Raises a X error [CODE]." In browsing for examples in the XQFO specs I was surprised that examples of errors were relatively sparse. |
Thanks for the valuable feedback, @Arithmeticus . I reflected your comments. Please, do have a look |
The CG agreed to accept this PR at meeting 051 |
Added fn:chain.
Took much effort to ensure Unix-style line-endings are used.