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

• To: mathgroup at smc.vnet.net
• Subject: [mg64931] Re: Listable functions with two brackets f[][] (SubValues)
• From: dh <dh at metrohm.ch>
• Date: Wed, 8 Mar 2006 00:59:43 -0500 (EST)
• References: <dujrti\$923\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

Hi,
I can not see the benefit of using f[a_][b_] instead of f[a_,b_]. But if
you insists on using f[][]:
Consider f[a][b]: f[a] returns a function that takes [b] as argument.
Only a symbol can have the attribute "Listable". Therefore, f[a] can not
have the arttribute "Listable". It followes, that the definition has to
be done in 2 stages. First we define the "inner" function and make it
listable:

Remove[f1,f2];
f1[fun_,a_Line]:=Line[fun /@ a[]];
SetAttributes[f1, Listable]

now we define the final function f2[][] using f1:

f2[vec_][a_]:= f1[#+vec &, a]

this will now work as you want:

f2[{1, 3}][c]
f2[{1, 3}][b]

Daniel

Goyder Dr HGD 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.?
>
> 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:=
> ClearAll[f];
> f[vec_][a_Line] := Line[(#1 + vec & ) /@ a[]]
>
> In:=
> b = Line[{{1, 2}, {3, 4}, {5, 6}}];
>
> In:=
> f[{1, 3}][b]
>
> Out=
> 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:=
> c = {b, Line[{{2, 3}, {5, 6}, {9, 3}}]};
>
> In:=
> f[{1, 3}][c]
>
> Out=
> f[{1,3}][{Line[{{1,2},{3,4},{5,6}}],Line[{{2,3},{5,6},{9,3}}]}]
>
> Attempts to make the function f[][] Listable fail because it makes the
> first and not the second bracket Listable.
>
> In:=
> SetAttributes[f, Listable]
>
> In:=
> f[{1, 3}][c]
>
> Out=
> {f,f}[{Line[{{1,2},{3,4},{5,6}}],Line[{{2,3},{5,6},{9,3}}]}]
>
> Is there a solution?
>
> Thanks
> Hugh Goyder
>

• Prev by Date: Re: Possible Bug in ArcTan ?
• Next by Date: Re: Plus Behavior Inside a Notation Box?
• Previous by thread: Re: Listable functions with two brackets f[][] (SubValues)
• Next by thread: Re: Listable functions with two brackets f[][] (SubValues)