Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I pass a variable through multiple inner functions in KDB?

I’ve got a function peg:

  peg: {{$[abs[log x%y]>0.06;y;x]} scan x} 

The 0.06 is a parameter that I’d like to pass to peg from the outside, so I can do something like 0.06 peg x.

What’s a clean way of passing this variable through?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You could rewrite the function to add explicit variables so you can keep the local variable names as x and y. Below I’ve added a new argument v for the value you want to pass.

peg: {[v;x]{[v;x;y]$[abs[log x%y]>v;y;x]}[v] scan x}

peg[0.06;x]

I don’t think there’s any other easy way to do this.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading