Skip to content

Explicitly mention bidirectional parameter flow inside variable scoping documentation #691

Description

@Bertie690

Currently, the page on scoping within GritQL fails to clearly mention a notable fact about patterns - parameters flow bidirectionally across boundaries.
Any metavariables passed as parameters will be mutated upon returning to the calling scope, a concept that I only discovered after trying random stuff on the playground for 2 hours straight.

As such, I suggest adding an example where a pattern is used to "bind" portions of a larger match to variables at callsites.

Contrived example snippet

// matches an `expect(x).toBe(y)` call and binds the results to `name` and `value`.
pattern match_expect($name, $value) {
    `expect($name).toBe($value)`
}

// n and v are filled in with the values set during match_expect
match_expect(name=$n, value=$v) where {
    $n <: `foo` => `bar`,
    $v <: `baz` => `quux`,
}

converts expect(foo).toBe(baz) ==> expect(bar).toBe(quux)

Note

I put this here mainly for inspiration; you folks can likely come up with much better examples than me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions