ER: ignore `module` directive (for the time being)
pkoppstein opened this issue · comments
Perhaps one day jaq will support modules in some shape or form.
In the meantime, it would be very helpful if jaq could at least ignore a valid jq "module" directive
to facilitate the use of otherwise-compatible jq modules.
Thanks!
Hi @pkoppstein, I have also planned module support for 2.0. I'm not sure, though, about whether it's worth to support the module
directive, because it is only useful together with metadata, but is this actually used in the wild?
By the way, you might perhaps know this: If we import some JSON data in a module mod.jq
, then we can use it inside this module, e.g.:
# mod.jq
import "bench" as $bench;
def x: $bench::bench;
If we import this module, can we refer to variables such as $bench
from there?
import "mod" as mod;
mod::x, # <--- this works
$mod::bench::bench # <--- this does not compile
I suppose that this is not possible, but I guessed that I'd better ask. :)
@01mf02 asked:
is this actually used in the wild?
Yes. See e.g.
- https://github.com/stanch/jq-modules/blob/master/cf-sg-graph.jq
- the many modules at https://github.com/fadado/JBOL
- the modules listed at https://rosettacode.org/wiki/Category:Jq
@01mf02 wrote:
$mod::bench::bench
I would not expect that to work, because "mod" has been imported as a jq module, not as data.
Given your setup, however, one might reasonably expect mod::$bench::bench
to work, but it doesn't (at least not yet :-)
As far as I can tell, not much thought was given to the importation of "data" (i.e. using the import directive) so I wouldn't read too much into the way things actually work. (In this regard, it's noteworthy that one can write $bench
as well as the documented and somewhat mysterious $bench::bench
.)
Should we request mod::$bench::bench
as an "enhancement request"?
Thanks for giving some examples of module
in the wild, @pkoppstein. I'm convinced now that I want to support this.
Also thanks for pointing out that $bench alone works as well. I thought that I had tried that and it didn't work, but I checked again just now, and it worked just fine. In that case, I think that I'd rather not support $bench::bench
, but just the shorter (and more logical, IMO) $bench
.
No, let's not request mod::$bench::bench
; it will be enough work for me to get jaq on the same level as jq module-wise without this feature. ;)