miller icon indicating copy to clipboard operation
miller copied to clipboard

Feature request: `#include` statements for DSL

Open vapniks opened this issue 2 years ago • 3 comments

I'm steadily building a library of functions written in the miller DSL. It would be useful to be able to source them into my scripts with a c-style #include statement.

vapniks avatar Jun 28 '23 17:06 vapniks

@vapniks thanks for the request. I've never been eager to go this route -- C's include pattern has been (IMO) an antipattern over the years; being moved away from in other languages since, such as Java and Go; and C++ itself is moving (albeit slowly) along the module route and away from includes.

At a more concrete level, there are potential user-level confusions such as having a #include line inside curly braces, difficulty debugging when the include is in the wrong place, difficulty debugging when the include is in the intended place but the code isn't functioning as desired. Also implementation-level snags such the possibility of infinite recursion.

I've instead leaned toward library-loading: here for example: https://miller.readthedocs.io/en/latest/reference-dsl-user-defined-functions/#loading-a-library-of-functions

If you haven't checked that out, please do! If you already have and it isn't working well for you, my preference would be to have a conversation about how to make it better fit your needs.

johnkerl avatar Jun 29 '23 13:06 johnkerl

Yeah, I saw that, but it means I (and anyone I share my code with) have to remember to type it on the command line every time :(

vapniks avatar Jun 29 '23 23:06 vapniks

FYI there is a support for @include in GNU awk (aka gawk). The gawk manual also describes how to code the feature for other awks, to make awk libraries more portable.

I think this basic gawk-like feature would be welcome by miller users, no need for anything complicated like in C, imho.

janxkoci avatar Jul 31 '23 16:07 janxkoci