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

(1) add method IO::Path.stemname; (2) expand method IO::Path.parts #5097

Closed
p6rt opened this issue Jan 28, 2016 · 5 comments
Closed

(1) add method IO::Path.stemname; (2) expand method IO::Path.parts #5097

p6rt opened this issue Jan 28, 2016 · 5 comments
Labels
RFC

Comments

@p6rt
Copy link

@p6rt p6rt commented Jan 28, 2016

Migrated from rt.perl.org#127407 (status was 'rejected')

Searchable as RT127407$

@p6rt
Copy link
Author

@p6rt p6rt commented Jan 28, 2016

From @tbrowder

Class IO​:Path currently has many methods for handling path name. The
list currently includes​:

method abspath
method basename
method extension
method dirname
method volume
method parts
method path
method Str

I would like to see a new method named, say, stemname, which would be
similar to basename except any suffix is removed.

# existing method​: basename

say IO​::Path.new("docs/README.pod").basename;
README.pod

# existing method​: extension

say IO​::Path.new("docs/README.pod").extension;
pod

# new method​: stemname

say IO​::Path.new("docs/README.pod").stemname;
README

# updated old method​: parts

say IO​::Path.new("docs/README.pod").parts.perl;
{​:basename("README.pod"), :directory("doc"), :dirname("doc"),
:volume(""), :basename("README.pod"); :stemname("README")}

Best regards,

-Tom

@p6rt
Copy link
Author

@p6rt p6rt commented Jan 14, 2017

From @smls

I would like to see a new method named, say, stemname, which would be
similar to basename except any suffix is removed.

Isn't that what the word `basename` conveys too?

After all, the purpose of the well-known `basename` POSIX utility is to return the filename with its suffix stripped. It's just that it doesn't guess what you want to consider a suffix, so it strips nothing as an edge case when no suffix list is specified.

I'd thus consider the Perl 6 `.basename` method a misnomer, since its purpose is to always return the whole filename.

Ideally, Perl 6 would provide​:

  `.filename` -- whole filename
  `.basename` -- filename without suffix

I suppose `.stemname` is a decent synonym for `.basename`, so a plan forward without much backwards compatibility breakage could be​:

1) Introduce `.stemname` as this RFC suggests.
2) Introduce `.filename` as a synonym to `.basename`.
3) Deprecate `.basename` with a long deprecation cycle.

(Another candidate for deprecation would be `.dirname`, since AFAICT it's redundant with the much more clearly named .parent. And lets not even get into `.abspath` and `absolute` both existing, and the inconsistency of some routines returning paths as IO​::Path and others returning paths as Str. Yeah, there's a lot of cleanup potential in the IO parts of the language...​:P)

@p6rt
Copy link
Author

@p6rt p6rt commented Jan 14, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

@p6rt p6rt commented Apr 19, 2017

From @zoffixznet

On Thu, 28 Jan 2016 10​:45​:04 -0800, tbrowder wrote​:

Class IO​:Path currently has many methods for handling path name. The
list currently includes​:

method abspath
method basename
method extension
method dirname
method volume
method parts
method path
method Str

I would like to see a new method named, say, stemname, which would be
similar to basename except any suffix is removed.

# existing method​: basename

say IO​::Path.new("docs/README.pod").basename;
README.pod

# existing method​: extension

say IO​::Path.new("docs/README.pod").extension;
pod

# new method​: stemname

say IO​::Path.new("docs/README.pod").stemname;
README

# updated old method​: parts

say IO​::Path.new("docs/README.pod").parts.perl;
{​:basename("README.pod"), :directory("doc"), :dirname("doc"),
:volume(""), :basename("README.pod"); :stemname("README")}

Best regards,

-Tom

Thanks for the suggestion, however, I'm going to reject this RFC.

You showed the most common example—a single part extension—but it has the same limitations as the old .extension method (e.g., I'd expect the "stemname" of "foo.tar.gz" to be "foo" not "foo.tar").

As of Rakudo 2017.04.2, you can use .extension method remove the extension, removing however many parts you want to remove, and you can then call .basename on the returned path to get the "stemname"​:

  "docs/README.pod".IO.extension("").basename.say
  # OUTPUT​: README

  "docs/foo.tar.gz".IO.extension("", :2parts).basename.say'
  # OUTPUT​: foo

@p6rt
Copy link
Author

@p6rt p6rt commented Apr 19, 2017

@zoffixznet - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this Apr 19, 2017
@p6rt p6rt added the RFC label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant