Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14431

Re: Listable Attribute of Pure Function that returns a matrix

From albert.retey@gmail.com
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Listable Attribute of Pure Function that returns a matrix
Date 2013-05-07 07:53 +0000
Message-ID <kmabt9$qd3$1@smc.vnet.net> (permalink)
References <km7oig$j75$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


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]

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Listable Attribute of Pure Function that returns a matrix Dan O'Brien <danobrie@gmail.com> - 2013-05-06 08:10 +0000
  Re: Listable Attribute of Pure Function that returns a matrix albert.retey@gmail.com - 2013-05-07 07:53 +0000

csiph-web