Show HN: Jacinda, a functional Awk (text stream processing on the comamnd-line) (hackage.haskell.org)
Typed, functional (folds, scans) stream processing backed by Andrew Gallant/burntsushi's regular expressions library.
There's a guide here! https://vmchale.github.io/jacinda/
16 comments
[ 2.6 ms ] story [ 34.2 ms ] threadThe colon being used in multiple contexts is tricky. As I was scanning the examples I found postfix `:` doing type conversion like in `(%)\. {%/Apple/}{`3:}` and then I was wondering what it does when it has nothing on its left-hand side, like in `[(+)|0 [:1"x]`. Then I noticed that the [ were unbalanced in the latter example, and eventually figured out that `[:` is its own operator separate from `:` and the middle `[` had nothing to do with function syntax.
When I think about how I use awk, I think it’s mostly something like:
Or Or just as an advanced version of cut. A fourth example is something that is annoying to do in a streaming way but easy with bash: compute moving average of second field grouped by third field over span of size 20 (backwards) in first field. The above all feel somewhat functional as computations – the first is a folding filter, the second a fold, the third a map, and the fourth is a folding concat map if done on-line or a concat map followed and a folding map as written.The awk features that feel ‘non-functional’ to me are less the mutation and more operations like next, or the lack of compositionality: one can’t write an awk program that is, in some sense made of several awk programs (i.e sets of pattern–expr rules) joined together. That compositionality is the main advantage, in my opinion, of the ‘functional’ jq, which feels somewhat awk-adjacent. Is there some way to get composition of ja programs without falling back to byte streams in between?
I’m not sure I really understand the language (and I definitely don’t understand the implementation!) but it seems pretty interesting. Perhaps a better motto than “functional awk” is “streaming APL with type checking (and type classes)”?
What do you use instead of grep on the CLI? Or do you "trust regex" when using grep?
Part of the point of publishing open source software is that many eyes make bugs (and documentation errors) shallow.
People make mistakes, links rot, etc. It's not a sensible generalization and there's this thing:
Please don't pick the most provocative thing in an article or post to complain about in the thread. Find something interesting to respond to instead.
https://news.ycombinator.com/newsguidelines.html
If you are doing sometime repeatedly, especially if it's automated, then yes, if possible you should write/adopt a real parser and add error handling and such.
ETA: A notable exception is file paths and similar. Regexes are a totally acceptable way to parse those (modulo issues like escaping user input).