-
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
New functions fn:foot, fn:truncate, array:foot, array:truncate #250
Conversation
Is it worth adding an optional length parameter?
etc. Similar effects could be obtained in the related funtions (including
Where +n means the first n items and -n means all but the last n items. This is not a new idea, it's what the Linux |
Personally, I would prefer to keep head, tail, foot and truncate simple and straightforward. I think that the new |
Fair enough, @ChristianGruen. I'm fine with keeping it simple, just thought I'd raise the thought because it occurred to me. |
I had the same thoughts myself ((a) adding a length argument, and (b) better to keep it simple and have an fn:slice that's all-singing-and-dancing). |
My objection against truncate would be that I know it from Sql where it means to clear entirely. If I understand correctly it would have the following meaning here: all but last. And the point that it is a verb is also speaking against simplicity and symmetry. But hey, for me tail was never intuitive either as it suggests some (small) end, not everything but the first. |
If the majority of the readers of my comment can guess what |
I asked my resident linguist for alternative pairs to go with |
"head" and "foot" is a very familiar pairing in the document/publishing world inhabited by many of our users, so I see no problem with it. I'm personally happy with truncate because it matches the natural-language meaning of "cut off the end" and because I can't think of anything better. My next choice would be remove-last(), reflecting the existing usage of "remove" and "last" in the language. It would be a mistake to ignore the cultural traditions of the language we are curating. The nomenclature tradition is to avoid quirkiness, jocularity, and excessive brevity, but at the same time to avoid excessive pedantry. Function names can be verbs (translate), verb-noun combinations (parse-json, resolve-uri, is-NaN), nouns (head, tail, subsequence, root), adjectives (size, string-length, upper-case) or pretty well anything else, but they are invariably combinations of one or more meaningful English words or common words of art such as "URI"; the only exceptions are where we have borrowed well known function names from other languages, such as avg and cos, min and max. |
I was just exploring the design space a bit. I concur that nothing really pairs with "foot" and has the same strength of analogy as head/tail. I can live with |
Me too. If we had |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe item in a sequence
→ item of a sequence
?
I have a few remarks I would like to make. First, I still believe that |
@PieterLamers The terms "head" and "tail" are well established in other functional programming languages, and now in XPath 3.1, and there is absolutely no point in changing them even if we were convinced they could be improved. (If there is one existing function name I would like to change, it is "contains()", but the fact that 95% of users use it correctly and 5% incorrectly isn't a sufficient case for changing it). For anyone working with documents, "head()" and "foot()" are very natural complements for the beginning and end of something; everyone knows what headers and footers are. And For truncate(), I suggest that if we can't find a term that everyone finds acceptable, we simply drop the idea. It's easy enough to live without it. |
A strong +1 for keeping it. I see many use cases for having reverse versions of Still, the function is not essential enough to spend much more time on finding a/the perfect name. |
It’s entertaining to see that our discussion has, of course, been held for other programming languages before. Maybe some of you know Lisp provides a But I tend to claim that no one has come up with a flawless solution, and I’d be happy with both a self-explanatory |
My two cents on the naming issue.
The programmer is invited to think of sequences with an anatomical metaphor with I recommend for the complement of Possibilities for (1): Possibilities for (2): Possibilities for (3) |
I think it's only disorienting because you're thinking of the four functions as a group. If you think of Of course, we could get used to |
Exactly. I would be happy with |
If that were the direction, I would opt for Of the options I provided I think that |
Oops, I meant a 2-arity version of It makes me wonder if the complement of |
My personal hope would have been to have a symmetric counterpart for |
For more flexibile functions, we should look again at things like |
Agreed in principle at meeting 014 on 6 December 2022. Merging with two approvals. |
New functions fn:foot, fn:truncate, array:foot, array:truncate, as proposed in issue #97. Note that not everyone was happy with the name "truncate".