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

• To: mathgroup at smc.vnet.net
• Subject: [mg64926] Re: [mg64909] Listable functions with two brackets f[][] (SubValues)
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Wed, 8 Mar 2006 00:59:37 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```ClearAll[f];
f[vec_][a_Line]:=Line[(#+vec&)/@a[]];
f[vec_][a:{_Line..}]:=f[vec][#]&/@a;

b=Line[{{1,2},{3,4},{5,6}}];

f[{1,3}][b]

Line[{{2, 5}, {4, 7}, {6, 9}}]

c={b,Line[{{2,3},{5,6},{9,3}}]};

f[{1,3}][c]

{Line[{{2, 5}, {4, 7}, {6, 9}}], Line[{{3, 6}, {6, 9}, {10, 6}}]}

Bob Hanlon

>
> From: "Goyder Dr HGD" <h.g.d.goyder at cranfield.ac.uk>
To: mathgroup at smc.vnet.net
> Date: 2006/03/07 Tue AM 06:12:03 EST
> Subject: [mg64926] [mg64909] Listable functions with two brackets f[][]  (SubValues)
>
> 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
>
> --
> This message has been scanned for viruses and
> dangerous content by the Cranfield MailScanner, and is
> believed to be clean.
>
>

```

• Prev by Date: Open Source IMTEK Mathematica Supplement (IMS)
• Next by Date: Re: Listable functions with two brackets f[][] (SubValues)
• Previous by thread: Re: Listable functions with two brackets f[][] (SubValues)
• Next by thread: Re: Listable functions with two brackets f[][] (SubValues)