admin管理员组文章数量:1356275
I have below function for fibonacci which is returning expected output
q)fib:{{x,sum -2#x}/[{last[x] < 100};x]}
q)fib 1 1
1 1 2 3 5 8 13 21 34 55 89 144
How could we replace the value 100 in the inner function {last[x] < 100}
with an argument from the outer function?
Expected function call structure -
q)fib[1 1;100]
1 1 2 3 5 8 13 21 34 55 89 144 /- expected output
I have below function for fibonacci which is returning expected output
q)fib:{{x,sum -2#x}/[{last[x] < 100};x]}
q)fib 1 1
1 1 2 3 5 8 13 21 34 55 89 144
How could we replace the value 100 in the inner function {last[x] < 100}
with an argument from the outer function?
Expected function call structure -
q)fib[1 1;100]
1 1 2 3 5 8 13 21 34 55 89 144 /- expected output
Share
Improve this question
asked Mar 30 at 16:13
UtsavUtsav
5,9622 gold badges35 silver badges56 bronze badges
2 Answers
Reset to default 2Here's one way
q)fib:{{x,sum -2#x}/[{last[y]<x}y;x]}
q)fib[1 1;100]
1 1 2 3 5 8 13 21 34 55 89 144
You can also drop the inner lambdas and use compositions:
q)fib:{{x,sum -2#x}/[y>last@;x]}
q)fib[1 1;100]
1 1 2 3 5 8 13 21 34 55 89 144
q)
q)fib:{(y>last@){x,sum -2#x}/x}
q)fib[1 1;100]
1 1 2 3 5 8 13 21 34 55 89 144
本文标签: kdbWhile condition for iterator to be passed as argument of a functionStack Overflow
版权声明:本文标题:kdb+ - While condition for iterator to be passed as argument of a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743982648a2571145.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论