MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Listable functions with two brackets f[][] (SubValues)

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64950] Re: Listable functions with two brackets f[][] (SubValues)
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Wed, 8 Mar 2006 01:00:57 -0500 (EST)
  • Organization: The University of Western Australia
  • References: <dujrti$923$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <dujrti$923$1 at smc.vnet.net>,
 "Goyder Dr HGD" <h.g.d.goyder at cranfield.ac.uk> wrote:

> I would like to use a double bracket function f[][] as, I believe,
> originally promoted  by David Park. The second bracket is called the
> SubValues of f.  My problem is that I would like the second bracket to
> be Listable. Is this possible.?

AFAIK, not using the Listable Attribute -- but you can easily get the 
behaviour you want.

> The following is a toy example by way of illustration.  Suppose I wish
> to make a function that translates the graphics primitive Line. Then I
> can make a function as follows and it works for one Line[].
> 
> In[1]:=
> ClearAll[f]; 
> f[vec_][a_Line] := Line[(#1 + vec & ) /@ a[[1]]]

Alternatively, you could write

   f[vec_][Line[a_]] := Line[(# + vec &) /@ a]

> In[3]:=
> b = Line[{{1, 2}, {3, 4}, {5, 6}}]; 
> 
> In[4]:=
> f[{1, 3}][b]
> 
> Out[4]=
> Line[{{2,5},{4,7},{6,9}}]
> 
> However, if I have a list of Lines[]  it does not work because the
> second bracket does not have the Attribute Listable. 
> 
> In[5]:=
> c = {b, Line[{{2, 3}, {5, 6}, {9, 3}}]}; 
> 
> In[6]:=
> f[{1, 3}][c]
> 
> Out[6]=
> f[{1,3}][{Line[{{1,2},{3,4},{5,6}}],Line[{{2,3},{5,6},{9,3}}]}]

Just add the rule

  f[vec_][a_List] := f[vec] /@ a

and then try 

  f[{1, 3}][c]

again.

> Attempts to make the function f[][] Listable fail because it makes the
> first and not the second bracket Listable.
> 
> In[7]:=
> SetAttributes[f, Listable]
> 
> In[8]:=
> f[{1, 3}][c]
> 
> Out[8]=
> {f[1],f[3]}[{Line[{{1,2},{3,4},{5,6}}],Line[{{2,3},{5,6},{9,3}}]}]
> 
> Is there a solution?

Not using Listable, I think.

Cheers,
Paul

_______________________________________________________________________
Paul Abbott                                      Phone:  61 8 6488 2734
School of Physics, M013                            Fax: +61 8 6488 1014
The University of Western Australia         (CRICOS Provider No 00126G)    
AUSTRALIA                               http://physics.uwa.edu.au/~paul


  • Prev by Date: Re: Plus Behavior Inside a Notation Box?
  • Next by Date: Re: Compile Fourier (2)
  • Previous by thread: Re: Listable functions with two brackets f[][] (SubValues)
  • Next by thread: Re: Does Mathematica run on HP-UX (Itanium) ?