KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums KX Academy terminating condition for iterators Reply To: terminating condition for iterators

  • megan_mcp

    Administrator
    July 22, 2024 at 3:06 pm

    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