Variable scoping in KDB
getQuotes: {[sym;start;end]
url: f[sym;start;end]
{some_test} {request.quotes[url;x`next_page_token]} \ request.quotes[url;0b]
}
I have a while
loop. The issue I'm having is that url
is out of scope for the while lambda:
'url
[2] alpaca.q:47: .alpaca.getQuotes@:{request.quotes[url;x`next_page_token]}
^
I have read on this post that this is by design: Variable scope propagation in k, but it doesn't really give me a solution.
I've tried to wrap it in a unary, which didn't work.
I made url
global with url::
, this did work, but it's not very clean.
Is there a preferred pattern for passing url
into the lambda?
You can pass variables into the inner lambdas as parameters:
getQuotes: {[sym;start;end]
url: f[sym;start;end]
{some_test} {[x;url]request.quotes[url;x`next_page_token]}[;url] \ request.quotes[url;0b]
}