Skip to content

documentation of a significant jq/gojq inconsistency re $-variables in function definitions #107

@pkoppstein

Description

@pkoppstein

jq handles "$-arguments" in function definitions as implicit "as" statements,
whereas gojq does not. This introduces a source of potential inconsistency.

Consider for example:

def prod: .[0] * .[1];
def prodEqual($p): prod == $p;

This works as expected in both jq and gojq.

However, if prodEq were defined as:

def prodEq($prod): prod == $prod;

then we would see the discrepancy, as jq implicitly expands
the definition of prodEq to

def prodEq($prod): prod as $prod | prod == $prod;

Because of shadowing, in jq, prodEq would therefore always returns true!

For example:

[1,1] | prodEq(0) #=> true using jq
[1,1] | prodEq(0) #=> false using gojq

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions