Quick Question about the use of @

Dear All,

Please read the code below:

First, I define this:

apply:{[container; indices; function]

    result: container;

    result[indices]: function each container indices;

    : result};

which is similar to the function of “@”. This way is what I learned from ( http://www.kdbfaq.com/kdb-faq/how-do-i-use-the-functional-form-of-at-apply.html )

Second, I try this “apply”,

list: 1 + til 8;

apply[list; 0; neg];

the result is fine: -1 2 3 4 5 6 7 8

Third, I tried this on “apply”:

apply[`list; 0; neg]; 

but the compiler complaints : `type

why is this?

Thank you in advance?

Best Regards,

Wenhao SHE

In the third case, you’re applying the operation to a symbol. If you want to apply it to the data that the symbol represents then you would need to use “value” - either apply it to the symbol passed in or apply it within the analytic

q)apply[value `list; 0; neg]

-1 2 3 4 5 6 7 8

or?

apply2:{[container; indices; function]?

result:value container;

result[indices]: function each (value container) indices;

:result};

q)apply2[`list; 0; neg]

-1 2 3 4 5 6 7 8

Dear Terry Lynch,

Thank you very much for you help~~ It works now:D And your comments helped me to understand the dynamics behind.

Best Regards,

Wenhao SHE