Re: Listable Attribute of Pure Function that returns a matrix
- To: mathgroup at smc.vnet.net
- Subject: [mg130727] Re: Listable Attribute of Pure Function that returns a matrix
- From: albert.retey at gmail.com
- Date: Tue, 7 May 2013 03:53:28 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <km7oig$j75$1@smc.vnet.net>
Hi, > > Now, I do the same but instead I define a pure function > > In[37]:= ClearAll[func] > > SetAttributes[func, Listable] > > func = {{#1, #2}, {#3, #4}} &; > > func[a, b, c, Array[d, 4]] > > > > Out[40]= {{a, b}, {c, {d[1], d[2], d[3], d[4]}}} > > > > Clearly this is not behaving as a listable function, its simply > > substituting the list of d's for the 4th argument. > I think this is expected, although probably not easy to see from the documentation: if you want the pure function to be listable you need to set the Listable attribute to the pure function, not the symbol which happens to be set to that pure function. There is a special three argument form of `Function` which allows to do that and a undocumented (?) feature which lets you use that three argument form and still use the Slot-syntax for the one-argument form. Searching for Function and Slot in the documentation will give you some more details and examples. Altogether this should work: func = Function[Null, {{#1, #2}, {#3, #4}}, Listable]