1. 43
    1. 9

      I’ve dipped my toe in Awk programming previously, and while there’s parts of awk that feel like any modern scripting language (or even better, for the tasks awk was designed for), there’s also weird bits that aggressively remind me it was designed in the 1970s:

      • string functions generally don’t return strings; for example, Python’s parts = text.split() in awk is split(text, parts) and returns the new length of parts
      • you can declare functions, but not local variables; apparently the convention is to add extra function arguments and just never provide them at the call site, so the function can clobber them
      • all strings are byte strings, even in a UTF-8 locale (this is not true in gawk, but mawk is so much faster in general)

      Despite all those things, awk is still a lot more pleasant that writing POSIX shell scripts for any kind of logic or computation, and very nearly as portable. A+, would use again.

      1. 9

        When I first started tinkering with Awk, the feature I found most surprising was that arrays are not first-class values; you cannot, for example, construct an array within a function and return it to the caller, or store a reference to an array in an array. Instead, functions which manipulate arrays must have them passed in by reference, possibly in combination with a length. The only true “values” are strings and numbers. This limitation is understandable in light of the many ways it simplifies an implementation of Awk, but it does reduce expressiveness considerably.

        There are a number of features I’d love to see added to Awk (proper local declarations, nested function declarations, perhaps utility functions for escaping special characters in strings to aid in the construction of dynamic regex patterns?), but if such features were added to any specific Awk implementation, the scripts that used them would no longer benefit from Awk’s portability.

        Awk is tantalizingly close to being an excellent general-purpose scripting language. At least what we have is quite useful!

        1. 4

          Yeah the way I phrase that is that awk isn’t a “GC complete” language (and neither are Bourne shell, CMake, fish). So you can’t return arrays from functions, or have recursive data structures (arrays in arrays)

          Review of Awk and Make After 6 years - https://www.oilshell.org/blog/2023/06/ysh-sketches.html#review-of-awk-and-make-after-6-years

          which links back to lobste.rs: https://lobste.rs/s/ijpr36/fascination_awk#c_9dgf4m


          But implementing a language with GC in awk is surprisingliy feasible! I didn’t quite realize that until Darius showed me this Lisp in 500 lines of Awk :)

          https://github.com/darius/awklisp/blob/master/awklisp

          Lila is similarly impressive! https://github.com/JohnEarnest/Decker/blob/main/tools/awk/lila.awk

      2. 3

        So Lil is a scripting language:

        https://beyondloom.com/decker/learnlil.html

        But there also seems to be another langauge named Lil:

        https://lil-language.com/

        1. 3

          For the record, I started designing and implementing Decker’s Lil (Learning In Layers) at roughly the same time Miro started his Lil (Lil Is a Language), and was not aware of his language until well after Decker’s release years later. The appearance, features, and application domains of these languages are dramatically distinct, and I do not believe anyone is likely to confuse them in practice. At any rate, the GitHub repository for Miro’s “Lil” does not appear to have been updated in two years, so it’s unclear whether the project is still active.

          Both of these contemporary Lils are also substantially predated by Kostas Michalopoulos’ “Little Interpreted Language”, a TCL-like, and in turn P. J. Plauger’s Little Implementation Language.

          1. 2

            Until yesterday I didn’t even know that there was a programming language named Lil, but it did sound interesting, and I was surprise to learn that there is more than one programming language that make claim to the name. And you even mention a third that goes by the same [abbreviated] name. Thanks for enlightening us.

        2. 2

          This is just lovely. Both the interpreter, and decker and lila :)

          1. [Comment removed by author]