3 ms·
Why is this article talking about idempotence? I don't see why that matters in the slightest for a unix pipe. Idempotence only matters if you're going to take t
by eridius 11y ago
Why is this article talking about idempotence? I don't see why that matters in the slightest for a unix pipe. Idempotence only matters if you're going to take the output of the pipe and run it back through the pipe again.
There's a bit later on about idempotence and newlines, but I don't see what that has to do with idempotence. Vim will append a trailing newline if the file doesn't have one, sure, but if I pass the output back through Vim again, it won't append another trailing newline, it'll just preserve the existing one, so if the vim command you run is idempotent then the whole thing will still be idempotent.
I'm guessing here that the author is simply confused about what idempotence means. Because of the newline bit, I'm going to guess that what the author means by "idempotence" is "any text that the vim filter isn't supposed to modify will be left exactly as found in the input", but that's not what idempotence is, and I'd also say that that property is pretty much a given for any kind of text transformation used in a pipe, because if it doesn't hold then why are you even using that tool?
- pjungwir 11y agoThat bugged me too, although it was such a fun article I didn't want to complain. :-) What he really means is that his first snippet is the identity function. Like x*1=x or x+0=x. Whatever it gets, it passes along unmodified. I think it's actually kind of nice that he started with that. Sometimes it is not easy to figure out how to do, for instance with XLST.....
- robertelder 11y agoYeah, an identity function is probably what I should be calling it instead.
- robertelder 11y agoI suppose you're correct about the terminating newline case, in that the newline is only added once. I'm not sure what you'd call it, but I'm talking about it as if it were a kind of idempotent 'base case'. For example: If you do echo -en "" | ( (vim - -esbnN -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | xxd versus echo -en "" | ( (vim - -esbnN -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | ( (vim - -esbnN -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | xxd These will the same output, so it is idempotent. However, if you build upon that and do echo -en "" | ( (vim - -esbnN -c '%!xxd' -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | xxd versus echo -en "" | ( (vim - -esbnN -c '%!xxd' -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | ( (vim - -esbnN -c '%!xxd' -c 'w!/dev/stderr|q!' >/dev/null) 2>&1) | xxd The result is not the same, and therefore not idempotent if you plan to add extra -c commands.
- deleted 11y ago[deleted]