terminating condition for iterators

https://learninghub.kx.com/forums/topic/terminating-condition-for-iterators

not sure why the below does not work as it keeps causing crash in Jupyter Notebook?

{8>count x}{x,sum -2#x}\[0 1]

I understand the condition to terminate iteration can be placed inside function input, e.g. f[{condition};input] or {condition}f[input], for example this works as given in the notebook : {1000 > max x}{(+)prior x,0}\ 1

in general what is recommended ways to write conditions for terminating the "loop"/iteration ?

Thanks,



Hi @lestat-jin

The correct way to execute your answer would be to remove the square brackets:

{8>count x}{x,sum -2#x}\0 1

This is because we are looking for the dyadic form of the scan adverb 'x f\y'. Which if I use a parse tree to explain, would look like this:

q)-5!"{8>count x}{x,sum -2#x}\\0 1" / the correct version
(\;{x,sum -2#x})       
{8>count x}            
0 1                    

However if you use square brackets after scan, it forces it into monadic scan form, 'x[f\y]':

q)-5!"{8>count x}{x,sum -2#x}\\[0 1]"
{8>count x}
((\;{x,sum -2#x});0 1)

If you have any questions on this, please let me know!

Thanks,

Megan

Thanks a lot. could you explain why dyadic function is expected here? what is the f in "x f\ y" here? the {8>count x}{x,sum -2#x}\0 1 only takes one argument which is x...