Home › Forums › kdb+ › Five easy pieces #2: getting around › Re: Five easy pieces #2: getting around
-
Does the job! Note the use of a dictionary where another language would need a control structure.
The
each
can be dispensed with. Bothup
anddn
take vector arguments..Q.f
does not, sod[2]
could be.Q.f'[nd;]
:q)rnd:{[x;nd;m] d:`up`dn`nr!(up[;nd];dn[;nd];.Q.f'[nd;]); (d m) x} q)rnd[q+0 1 2;3;`up] "9.639" "10.639" "11.639" q)rnd[q+0 1 2;3;`nr] "9.639" "10.639" "11.639"
Now: can we eliminate repetition? The
up
anddn
functions differ by only a single keyword. And without delegating one of the modes to.Q.f
?(Hint: a single expression
rnd
is possible, ?80 characters.)