KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Dynamically project function Re: Dynamically project function

  • gyorokpeter-kx

    Member
    August 17, 2023 at 12:00 am

    In reality there is no such thing as a “zero-argument function” in q. Even if you don’t have an argument list and you don’t use any of x, y and z in your function, or if you specify the argument list as [], the function still has one argument. If you call a function with “no arguments” [], that actually means calling it with :: as an argument.

    Projection for the purpose of a deferred function call is achieved by adding a dummy argument, e.g. instead of

    fn: {[x] x+1};

    you would have

    fn: {[x;u] x+1};

    then fn[1] creates a projection that will execute the calculation with any argument passed.

    For the second question, one possible way is by composing a projection of enlist with the dot-apply of your function:

    q)proj:(‘)[fn .;(1; ; 3)]; q)proj .[{[x;y;z] x+y-z}]enlist[1;;3] q)proj 2 0 q)proj 10 8