cjm2671
cjm2671

Reputation: 19486

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

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

Upvotes: 1

Views: 416

Answers (3)

Matthew Madill
Matthew Madill

Reputation: 880

Alternative approach to apply each left

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

Upvotes: 2

terrylynch
terrylynch

Reputation: 13657

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

Upvotes: 1

Michael K
Michael K

Reputation: 226

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

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

Upvotes: 7

Related Questions