How can I run a list of functions on an input?

Viewed 152
q) ({2*x};{3*x})

How can I apply the list of functions to an input, e.g. 4, something like:

({2*x};{3*x})[4]
8 12
3 Answers

You should be able to use apply (@) each left (\:)

({2*x};{3*x})@\:4

Alternative approach to apply each left

q)({2*x};{3*x})[;4]
8 12

Just to generalise Michaels answer, if your function takes more than one input/parameter then you'd need to use dot-apply (.) rather than @. Dot-apply would work in both cases using:

q)({2*x};{3*x}).\:(),4
8 12
q)({y+2*x};{y+3*x}).\:(),4 100
108 112
Related