4 ms·
Is there a particular benefit in writing a VM in AWK, placed in a big BEGIN block? Very similar code can be written in Perl or Python. Isn't the strength of AWK
by bluetomcat 3y ago
Is there a particular benefit in writing a VM in AWK, placed in a big BEGIN block? Very similar code can be written in Perl or Python. Isn't the strength of AWK in its line-matching capability, being able to pattern-match a line against a block of code?
- siraben 3y ago> Is there a particular benefit in writing a VM in AWK Not really. Later on the book just ran out of line-matching examples to go through and started doing regular programming instead :P. When I actually write AWK code I rely on line-matching and using a variable to handle state.
- pdw 3y agoAt the time, awk was the only scripting language (other than shell) generally available on Unix systems. Perl, Tcl, Python didn't exist yet. So awk was often used for general-purpose programming.
- ufo 3y agoI love telling about that example to my programming language friends. > Hey you should read the AWK book, it even says how to write a VM! > Why would I ever want to use AWK for that? > Well, the input is a text file with one space-delimited instruction per line. > Hmm... You have a point.
- chasil 3y agoAWK runs everywhere. Perl and Python do not. Busybox has their own independent AWK implementation. https://busybox.net/ https://busybox.net/ https://frippery.org/busybox/ https://frippery.org/busybox/ Also see the first edition of the AWK manual online here: https://archive.org/details/pdfy-MgN0H1joIoDVoIC7 https://archive.org/details/pdfy-MgN0H1joIoDVoIC7
- unmole 3y agoI'm sorry, where does Awk run but Perl and Python don't? If we're counting minimalist implementations, there's micropython that even runs on microcontrollers that cost a less than 2 dollars.
- dredmorbius 3y agoThe POSIX standard mandates awk. It does not mandate Perl or Python. <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/awk.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/a...> <https://pubs.opengroup.org/onlinepubs/9699919799/utilities/contents.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c...> There are many systems which lack Perl or Python, but include awk. You might be carrying an Android device at the moment --- if you drop to its default userland, that provides a bunch of utilities, including awk, via Busybox. But not, so far as I'm aware, either Perl or Python. (You can of course install Termux which will then give you both Perl and Python, along with Node.js, ruby, and a whole slew of other scripting and compiled languages. But so long as we're considering stock installs, it's sed and awk.)
- paleface 3y agoSmall, embedded, busybox systems - per the parent comment.
- unmole 3y agoLike I said, MicroPython can run even on microcontrollers.
- paleface 3y agoI think parent may be more implying “living off the land” situations. Awk is ubiquitous, and part of the POSIX standard. Micro Python, not so much. I’m a big fan of Forth, but it’s not available everywhere. One has to adapt.