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

Option to run the program on each line of stdin #17

Open
dloscutoff opened this issue May 20, 2021 · 1 comment
Open

Option to run the program on each line of stdin #17

dloscutoff opened this issue May 20, 2021 · 1 comment

Comments

@dloscutoff
Copy link
Owner

Inspired by Perl's -n and -p flags, supposing we had one or two flags that ran an implicit loop over all lines of stdin and called the given code as a function on each line? I'm thinking something like this:

T (a:q) == ()
 P {

  ; Your code here

 } V (g PE a)

corresponding to perl -p and the same thing without the P for perl -n.

  • It loops over all lines of stdin and runs your code against each one.
  • The final expression in your code is autoprinted. You can specify whatever list format you like via command-line argument.
  • Inside your code, the line of stdin is a; the actual command-line arguments are still accessible as b through e and also @>g.
  • Global variables retain their values from one iteration to the next (unless you don't want them to, in which case you can lead with WG).
  • Your code can call itself recursively using f.

One question: what actual flags do we use, since -n and -p (and -P) are already taken--as are -e (for Each) and -l (for Line)?

@dloscutoff dloscutoff changed the title "Each line" flag(s) "Each line" functionality Sep 23, 2021
@dloscutoff dloscutoff changed the title "Each line" functionality Option to run the program on each line of stdin Sep 23, 2021
@dloscutoff
Copy link
Owner Author

Given the philosophy change in #42, flags should not be used for this purpose. But I think we could still implement the behavior using a character added to the beginning or end of the program.

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

No branches or pull requests

1 participant