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

“take” should leave what is left of the input pipe behind #923

Open
hanche opened this issue Feb 23, 2020 · 2 comments
Open

“take” should leave what is left of the input pipe behind #923

hanche opened this issue Feb 23, 2020 · 2 comments

Comments

@hanche
Copy link

@hanche hanche commented Feb 23, 2020

The take command, when given only one argument (take $n), behaves like take $n (all). In other words, it consumes the entire input pipe and returns the initial $n items ( is my prompt):

⬥ put a b c | { take 1; put ----; all }
▶ a
▶ ----
⬥ 

In the above example, I think the all command should get b and c. In other words, take $n should return the $n first items, and leave the rest for later commands to consume.

If the current behaviour is desired, one can always use take $n (all) or follow take $n by nop (all).

@krader1961

This comment has been minimized.

Copy link
Contributor

@krader1961 krader1961 commented Feb 24, 2020

Note that the Elvish documentation says the take command was inspired by the Haskell function of the same name. That documentation is unclear on what happens if take $n is shorter than the available values but implies the remaining values are left for subsequent functions. I've never written even a trivial "hello world" program in Haskell so I don't know how itstake function behaves. Nonetheless, the proposal by @hanche seems reasonable to me since it less likely to be confusing.

@hanche

This comment has been minimized.

Copy link
Author

@hanche hanche commented Feb 24, 2020

The take function in Haskell belongs to the pure part of the language, i.e., outside of the IO monad. In that context, the notions of “consuming” values or “leaving them behind” (or not) are meaningless. In other words, the second argument is left unchanged by the function, as it has to be in a functional language.

Elvish's two argument take is exactly the same. It is functional in nature, just as Haskell's.

My proposal is about the single argument take, which is a quite different beast, as it does IO and as such has side effects. It has nothing in common with the two argument take other than the name and a small bit of semantics. Moreover, my proposal is all about the side effects.

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
2 participants
You can’t perform that action at this time.