2

Is there a way to SetAttributes to a function defined like this:

fun[t_][x_,y_]

Something like SetAttrubutes[fun[t_],Listable]?

mattiav27
  • 6,677
  • 3
  • 28
  • 64

1 Answers1

5

You could make fun[t] return a pure Function and make that one Listable like this:

fun[t_] := Function[{x, y}, DoSomething[x, y, t], Listable];

Here is a simple example:

X = Range[5];
Y = Range[5];
fun[t][X, Y]

{DoSomething[1, 1, t], DoSomething[2, 2, t], DoSomething[3, 3, t], DoSomething[4, 4, t], DoSomething[5, 5, t]}

However, I believe to remember that there was some performance issue with pure functions with Listable attribute (at least in some version of Mathematica). It's been a while ago. Maybe this issue has been fixed already.

Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309