News for hackers. Stuff that matters.
Re:GNU Parallel, where have you been all my life? by cb321 on Monday August 21, 2023 @03:28PM (#37214196)
On Unix, you might try Nim (https://nim-lang.org) with https://github.com/Vindaar/shell and there are a slew of pipeline-y/Unix-y utilities over at https://github.com/c-blake/bu

Nim is statically typed and (generally) native-compiled, but it has very low ceremony ergonomics and a powerful compile-time macro/template system as well as user-defined operators (e.g., you can use `+-` to make a constructor for uncertain values so that `9 +- 2` builds a typed object as in https://github.com/SciNim/Measuremancer .

Re:GNU Parallel, where have you been all my life? by lysium on Monday August 21, 2023 @04:29PM (#37214937)
Thanks for pointing me to nim, it looks promising. I‘ll try to use https://nim-lang.org/docs/osproc.html to pipe programs.

My use case is approx. like this: I can get 80% what I want with ls … | sed … | grep -v … but then it gets complicated in the script and I’d like to replace the sed or grep part with some program.

Re:GNU Parallel, where have you been all my life? by cb321 on Monday August 21, 2023 @04:44PM (#37215116)
This sounds like a job for what standard C calls "popen". You can do

    import posix; for line in popen("ls", "r").lines: echo line
in Nim, though you obviously need to replace `echo line` with other desired processing and learn how to do that.

You might also want to consider `rp` which is a program generator-compiler-runner along the lines of `awk` but with all the code just Nim snippets interpolated into a program template: https://github.com/c-blake/bu/blob/main/doc/rp.md . E.g.:

    $ ls -l | rp -pimport\ stats -bvar\ r:RunningStat -wnf\>4 r.push\ 4.f -eecho\ r
    RunningStat(
      number of probes: 26
      max: 31303.0
      min: 23.0
      sum: 84738.0
      mean: 3259.153846153846
      std deviation: 6393.116633069013
    )
Re:GNU Parallel, where have you been all my life? by lysium on Tuesday August 22, 2023 @05:22AM (#37220364)
Thank you! Popen looks like what I was looking for!
Re:GNU Parallel, where have you been all my life? by cb321 on Tuesday August 22, 2023 @06:08AM (#37220662)
Sure. No problem.

While it may not be in any ANSI/ISO spec for C, even Windows has popen these days. There are some tiny popenr/popenw wrappers in https://github.com/c-blake/cligen/blob/master/cligen/osUt.ni...

Depending upon how balanced work is on either side of the pipe, you usually can even get parallel speed-up on multicore with almost no work. For example, there is no need to use quote-escaped CSV parsing libraries when you just read from a popen()d translator program producing an easier format: https://github.com/c-blake/nio/blob/main/utils/c2tsv.nim