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

Document lists.take-while #22

Open
blerner opened this issue Aug 15, 2017 · 6 comments
Open

Document lists.take-while #22

blerner opened this issue Aug 15, 2017 · 6 comments
Assignees

Comments

@blerner
Copy link
Member

blerner commented Aug 15, 2017

Once brownplt/pyret-lang#1134 lands, we'll have a new function take-while available, which takes a predicate and splits a list into a front and back part such that all the items in the front list pass the predicate, and the first item of the back list fails.

@blerner blerner self-assigned this Aug 15, 2017
@sorawee
Copy link
Contributor

sorawee commented Aug 15, 2017

Wouldn't span be a better name? (https://srfi.schemers.org/srfi-1/srfi-1.html#span). I would never think that take-while will do something like this.

@blerner
Copy link
Member Author

blerner commented Aug 15, 2017

No one knows about scheme :-) And "span" has no connotation of splitting a list into two related pieces; it sounds more like building a bridge or something.

We already have take that gives you a front prefix of a list of a given length; this is simply take combined with filter, in some sense.

Haskell (https://www.haskell.org/hoogle/?hoogle=takeWhile), Ocaml (http://batteries.forge.ocamlcore.org/doc.preview:batteries-beta1/html/api/List.html), .Net (https://msdn.microsoft.com/en-us/library/bb534804(v=vs.110).aspx), Clojure (https://clojuredocs.org/clojure.core/take-while), ReactiveX (http://reactivex.io/documentation/operators/takewhile.html) and plenty of others all call it take_while, but they're all dumb and don't return the back half of the list. So we're better ;-)

@sorawee
Copy link
Contributor

sorawee commented Aug 15, 2017

What about split-with? (https://clojuredocs.org/clojure.core/split-with)

Your example of take helps the argument that I'm going to make actually. We have take, drop, and split-at which operate on index. Traditionally, take-while and drop-while should be like take and drop that operates on predicate instead of index, so using the name take-while for the thing that should be similar to split-at is really misleading and inconsistent.

Two common names in other programming languages:

@jpolitz
Copy link
Member

jpolitz commented Aug 15, 2017 via email

@blerner
Copy link
Member Author

blerner commented Aug 15, 2017

I don't -- it doesn't tell me at all whether the split happens when the predicate goes from true to false, or vice versa. "Take while" to me at least connotes "while true" (as in, "get it while the getting's good")

Honestly I don't care enough about this to really complain, but I think all these names are pretty lousy and take-while seemed the best of the bunch to me.

@shriram
Copy link
Member

shriram commented Aug 15, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants