-1

I was trying to create a functional equivalent via:

q)buildQuery["update rnk:(rnk1+rnk2+rnk3+rnk4)%4 from t"]
"![t;();0b;(enlist`rnk)!enlist (%;(+;`rnk1;(+;`rnk2;(+;`rnk3;`rnk4)));4)]"

Consider the nested functional expression above:

(+;`rnk1;(+;`rnk2;(+;`rnk3;`rnk4)))

How can I generate it procedurally given the list below

`rnk1`rnk2`rnk3`rnk4
2
  • 1
    You're basically just calculating the average. Why don't you use avg ? Commented Apr 17 at 16:25
  • 1
    It would be helpful to know what buildQuery does or how it's defined Commented Apr 17 at 16:26

1 Answer 1

3

To answer your question directly, you can generate that construct using:

q){(+;y;x)}/[reverse`rnk1`rnk2`rnk3`rnk4]
+
`rnk1
(+;`rnk2;(+;`rnk3;`rnk4))

Alternatively, use a different formulation of your problem

update rnk:(+/)(rnk1;rnk2;rnk3;rnk4)%4 from t
/or
update rnk:sum(rnk1;rnk2;rnk3;rnk4)%4 from t

where both would parse into a form which would make using that list more direct

![t;();0b;(1#`rnk)!enlist(+/;(%;enlist,`rnk1`rnk2`rnk3`rnk4;4))]
![t;();0b;(1#`rnk)!enlist(sum;(%;enlist,`rnk1`rnk2`rnk3`rnk4;4))]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.