Better HN
topnewbestaskshowjobs
Log inSign up

jlp__inf

3 karma · joined Jun 8, 2024 (2y ago) · 10 submissions

j.larget-piet@proton.me
Submissions

comment 8mo ago · link · parent

thanks, i published an article draft about SAM inspired by your examples (referencing sources / this comment section)

Do not hesitate to pin point improvements.

comment 8mo ago · link · parent

and yess, g/PATTERN/ and /v/PATTERN/ are supzr powerful, creating branch conditions based on wether or not they (do not)match a PATTERN.

based on what you wrote:

i just add trailing \n normalization at the end

, x/(.+\n)+|\n+/ { g/./ x/\n/ c/ / v/./ c/\n/ } $ a/\n/ , x/\n+$/ c/\n/ w file_out.txt q

comment 8mo ago · link · parent

That's a fair analogy, i am taking the feedbacks into account.

comment 8mo ago · link · parent

Also, i managed to, i think simplify the second example to: 1,$-2 x/./ { a/->/ /./ t . } 1,$-2 { p } q

Which taught me a lot, because at first, i did not understand why we would stop at last line - 2 ($ - 2), but in fact yeah last line is the very last "\n", that is why we stop at $ - 2 to not do E->weird.

I'm starting to truly love sam

comment 8mo ago · link · parent

Thanks for those complementary informations.

Also, while i'm learning it, maybe that the sam traduction for the first file would be simpler, like:

,x/\n +/ c/ /

comment 8mo ago · link · parent

Thanks for sharing this, I’m learning a lot from it.

So if I understand correctly, it’s selection-based, right? You first select a region, and then you can apply further selections inside it?

So you kind of build nested selections to match exactly what you want (almost like a conditional tree).

And then you apply operations on the current selection

For example substitution with something like c/PATTERN/, is that correct?

comment 8mo ago · link · parent

Yup, notably the famous %s/PATTERN1/PATTERN2/g, which I suppose comes from sed

comment 8mo ago · link · parent

Ha, I went the Python → AWK → sed route, just for the sake of learning what was behind those chamanics expressions. Glad I could bring back those memories!

comment 8mo ago · link · parent

Yep, interesting, do you remember the initial text structure and operatins you would perform on it ?

comment 8mo ago · link · parent

Hi, I'm the author of the article, and sorry if it felt overly LLM-generated.

To clarify: I did spend quite a bit of time diving into `sed` myself (experiments, tests, etc.) and wrote an initial draft in French.

I then used ChatGPT to help me structure and refine the article in English to reach more people. But the core ideas and understanding come from my own exploration.

That said, I understand the concern, and for future articles I'll try to rely less on that kind of tooling for structure.

Happy to clarify or go deeper on any part of the article if needed.