4 ms·
Hi, I just wanted to tell you that I'm learning TXR right now (https://klibert.pl/output/this_week_on_polyglot.html https://klibert.pl/output/this_week_on_polyg
by klibertp 11y ago
Hi, I just wanted to tell you that I'm learning TXR right now (https://klibert.pl/output/this_week_on_polyglot.html https://klibert.pl/output/this_week_on_polyglot.html) and I like it very much. My current goal is to write a tutorial for it: the docs are good and pretty detailed, but they aren't exactly friendly to new users. I hope I'll manage to finish this, I think TXR deserves much wider recognition.
Anyway, thanks for your work on TXR and thanks for making it available. Great job!
- kazinator 11y agoHi. I think your code snippet: @ (block cd) @ (bind v @(get-string (open-command `cd @path && git remote -v`))) @ (next :string `@v`) @ (skip) vps@a(fetch) @ (bind url @(trim-str a)) @ (end) probably just wants to be something like perhaps this: @(next `!cd @path && git remote -v`) vps@\t@url (fetch) Match directly into the output of the git command with @(next ...), and extract the url directly: it is delimited by tab from the remote name (which we can use literally or represent using @\t) and by a space from the (fetch) or (push) keyword. Thus we can eliminate the trim-str extra step and variable. Also if v holds a string, `@v` simplifies to v! Another thing is that if we are just marching through data to produce output, and don't actually need to collect anything to analyze, we can convert this structure: @(collect) ...match... @(end) @(output) @ (repeat) ...spew... @ (end) @(end) into: @(repeat) ...match... @ (output) ...spew... @ (end) @(end) It's not just shorter, but efficient too if the data is large (it doesn't hang on to collected data as it marches through it). Cheers ...
- klibertp 11y agoThanks! I rewrote the example according to your suggestions. It's true that the part with @v, open-command, etc. wanted to be written differently. I realized that there has to be a better way of calling external command - I just couldn't find it then. Looking at the docs now, the meaning of ! is mentioned briefly: > The @(next) directive supports the file name conventions as the command line. The name - means standard input. Text which starts with a ! is interpreted as a shell command whose output is read like a file. These interpretations are applied after variable substitution. If the file is specified as @a, but the variable a expands to "!echo foo", then the output of the "echo foo" command will be processed. So it looks like I just missed it on my first reading.