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
Add .stem method to IO::Path for 6.e #5031
base: main
Are you sure you want to change the base?
Conversation
- stem: anything in basename before first ".", basename if no "." - suffix: anything in basename after first ".", "" if no "."
Suffix we basically already have, with the "extension" method. Adapted "stem" to take the number of extension levels to remove. By default all, * and Inf accepted as arguments. say "foo/bar.tar.gz".IO.stem; # bar say "foo/bar.tar.gz".IO.stem(1); # bar.tar
As another set of names for the basename’s parts, consider:
Thus only one new method need be added. |
Are you suggesting s/stem/barename/ ? Or are you suggesting that |
No.
Yes! |
Does it mean then that for a file.tar.gz.1:
|
.stem: file FWIW, I don't like "barename" as conceptually, people could think "file.tar" to be the barename of "file.tar.gz". I think |
I would say, that to me the argument is more about skipping from the end, not about leaving at the start. Normally we strip off extra extensions. Otherwise I may need to know how many extensions are there in order to strip the amount I need. There is a compromise option of |
No. For file <file.tar.gz.1>, my CURRENT recommendation is:
So only one change would be seen by the user. However, if @lizmat's change (my original suggestion) is kept, I believe the result should be:
And two changes would be seen by the user. |
I have a hard time seeing the use-case of these particular functions. What is want is the basename as implemented on the unix command line and in Perl: one that can remove a given suffix. Bonus points if it can take a junction of them but a list is acceptable too. Just give me a |
This would be my suggestion too. I guess it could be awesomified to accept matchers as well as strings for the suffixes to remove, but the basic idea seems good. |
I'm not clear in which direction this should go now, so closing this PR. I'd welcome any new PR with a clear definition and path forward (pun intended). |
I'll make one more observation. The one thing that bothers me about the current situation is the ease of determining the extension of a basename as contrasted with getting the basename without the extension. It just seems like there ought to be a simple, default method for doing so, regardless of what we call it. In pseudocode:
Each can have more complexities of use, but the default for getting the two pieces of the basename defined by the last dot in the name should need no arguments. |
I think the issue revolves around the question: "what is the extension?". On "foo.tar.gz", is the extension "tar.gz" or "gz" ? As long as we don't agree on the name, asking for a method that will give the basename "without the extension", will be impossible to give a good answer, let alone an implementation. |
I'm now arguing that the existing 'extension' method is fine. As a default, the extension captured should be the last one in basename as is the default now. The new direction I favor now has two parts:
You have basically solved Part 2. We just need to agree on Part 1. |
I think |
I think I can live with that since 'extension' gives me the last part (after the last dot) and 'stem' will give me the first part (before the first dot). That suits my usual use case:
And if 'suffix' becomes the basename remainder after the first dot, that can be useful, too. |
finding the "stem" of a file passed into a script is something i've had to do in every language. Yes, it's simple to combine If the argument against
I disagree. I don't think that's a "valid" question in this context. We've already got a If there's debate about what the "correct" extension is, then that should be taken up in a ticket about the
So, what's the historical resolution here? How has Raku decided on what name to use for things? I'm voting for "stem" because i haven't heard anything that's less ambiguous. Personally I don't really care. Every language has method names I disagree with. ;) |
"stem" takes the number of extension levels to remove.
By default all, * and Inf accepted as arguments.