Can I save a function as a file and call it when needed?

Hi, 

I’m wondering whether I can write a function and save it as a q script file, thus I can call it in other script when needed. 

For example, in MATLAB  I can write a function and save it as a .m file. Then I can call this function in any other script when needed. Or like python, import a function from .py file…  

If it wouldn’t work in q, is there a similar way of doing that? 

I’m a total newbie to KDB, any help is sincerely appreciated! 

Thanks,

Xinyu  

Hi Xinyu,

  • Save your function to a script, myfunctions.q
  • From the directory that contains the script, start a q session with:
    q myfunctions.q
  • OR within a q session, you can load a script with \l myfunctions.q
  • Use \f to return a list of functions defined in the session
    q) \f
       myfunc1

Hope this helps!

Thanks,
Matthew
AquaQ Analytics

Hi Matthew,

Thank you so much,  this is really helpful !!!

Best,

Xinyu