If your intent is to continue until more than 20 records in L, then you want to keep appending records to L until your condition is met. That indicates the While iterator.
The While iterator repeatedly applies a unary function f to an initial state until some test t of the state passes. Your initial state would be (();vals) an empty list and the values to work on. The function f will keep returning states until t applied to the latest state returns zero. Your solution is t f/(();vals) but what are f and t?
q)f:{list:x 0; v:x 1; (list,select from… first v;1_ v)}
Function f splits its argument into two. The Apply operator . will do that for us.
f:{(x,select from… first y;1_ y)}.
You guessed peach to iterate, but a peach slave knows only what it has retrieved itself. So the simple answer is to iterate as above on a single thread, comforted by the knowledge that V4.0 primitives seek opportunities to multithread. If peach saves you a lot of time, you could process chunks of vals, with t applied after each chunk.
HTH
Stephen
Stephen Taylor | Librarian | Kx | +44 7713 400852 | stephen@kx.com
If all you want is skip some vals (represented by x one at a time inside the function) if some condition is met then you can end the execution of myfirstrunearly. Let’s say vals is a list of symbols and L: select from trade where sym=x is a list of trades in a particular symbol.
myfirstrun:raze {[x] L: select from .... if[count[L] <= 20; :()]; // end early returning an empty list // do whatever you intended to do with L } peach vals;
If you want to exclude results that fail your test, you can get all of them and then apply the test. And peach is just fine for the iteration.
myfirstrun:raze{x where 20<count each x}{select from … x}peach vals
Suppose, as Igor and Alvi do, that you want to abort some substantial processing on the result sets. Let us represent that as a function sp.
myfirstrun:raze{x where 20<count each x}{sp select from … x}peach vals / choose when to apply sp!
You may find you can simply apply sp to the filtered results above:
myfirstrun:sp raze{x where 20<count each x}{select from … x}peach vals
Perhaps it must be applied individually to the filtered results:
myfirstrun:raze sp each{x where 20<count each x}{select from … x}peach vals
Worst case, it must be applied within your lambda. Many writers reserve the if control word for side effects, and the if[… ; :res] construction to returning error messages. Functional style would use Cond: