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

Normalize the argument order in lstrip and rstrip #27605

Merged
merged 2 commits into from
Jun 19, 2018

Conversation

ararslan
Copy link
Member

This puts the function argument first, as dictated in the style guide.

@simonbyrne
Copy link
Contributor

Link to old discussion in #27211, #27232 and #27309.

@ararslan
Copy link
Member Author

There was general agreement that we should at least allow the function argument first.

As I said in one of those, this will just be a weird case of "oh yeah, functions come first everywhere but this one oddball case," like we had then fixed with finalizer.

@JeffBezanson
Copy link
Member

This very closely resembles the drop-while function found in many functional languages, where the predicate (as always!) is the first argument.

I believe I've read all the threads on this, and I don't see a single good argument for why the function should go second in just this case. @KristofferC said he finds it more natural to put the function second, and that's it. That doesn't seem like enough to overrule a strongly established convention here. If people want the option to pass the function second as well, and that doesn't cause any ambiguities, then I guess that's fine in addition.

@strickek
Copy link
Contributor

Maybe it is also useful to have a method for 3 arguments: Strip if function is true or in chars. eg

lstrip(isnumeric, "0123abc", ['a', 'b']) == "c"

@ararslan
Copy link
Member Author

Seems that could be written more clearly as

lstrip(c->isnumeric(c) || c in ['a','b'], "0123abc")

@strickek
Copy link
Contributor

You are right, it would be better to do it in this way.

@@ -135,15 +135,16 @@ function chomp(s::String)
end

"""
lstrip(str::AbstractString[, chars])
lstrip([pred,] str::AbstractString[, chars])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not allowed to supply both pred and chars so this should be two separate signatures, something like this:

lstrip([pred=isspace,] str::AbstractString)
lstrip(str::AbstractString[, chars::Base.Chars])

@StefanKarpinski
Copy link
Member

Yes, I think this is the right move.

@ararslan
Copy link
Member Author

I also removed the reference in DelimitedFiles to _default_delims, which no longer exists, that's causing a warning during the build.

@strickek
Copy link
Contributor

strickek commented Jun 18, 2018 via email

@StefanKarpinski
Copy link
Member

Yes, of course, you're right, @strickek.

@ararslan
Copy link
Member Author

Good catch, @strickek, thanks!

@ararslan
Copy link
Member Author

The CI failures are unrelated: FreeBSD froze and Circle got OOM killed. Good to merge?

@ararslan ararslan merged commit 8fc7a16 into master Jun 19, 2018
@ararslan ararslan deleted the aa/functions-come-first branch June 19, 2018 04:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
strings "Strings!"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants