QSQL - Names in subphrases

Hi Team,

I have a question regarding the namespace resolution in QSQL subphrases.

In the language doc: https://code.kx.com/q/basics/qsql/#names-in-subphrases , it mentions that

  • A name in a subphrase is resolved (in order) as the name of

Could you help explain why the space in which the function was defined was skipped? Aka why not

  • column or key name

  • local name in (or argument of) the encapsulating function

  • names in the space in which function was defined

  • global name in the current working namespace

The following code illustrates that: indeed, the namespace in which the function was defined is skipped.

Because, if we call my_func in the update clause, q will complain with: 'my_func.

Instead, if we call with .test.my_func, it works ok.

 

system “d .test”; my_func: { (abc!aabaca) }; my_main: {[t] show my_func; /tbl: update my_func each col1 from t; / NOT work tbl: update .test.my_func each col1 from t; / work OK tbl }; system “d .”; t: ( col1: aabcba`d; col2: 1 2 3 4 5 6 7); show .test.my_main[t]; exit 0;

 

However, this feature is not that intuitive. I believe it makes sense for a user to define a helper function within a namespace and use that directly in subsequent “main” functions.

Would you please explain the reason behind the current rule of “Names in subphrases”? Thanks.