Re: Format
- To: mathgroup at smc.vnet.net
- Subject: [mg111582] Re: Format
- From: Ray Koopman <koopman at sfu.ca>
- Date: Fri, 6 Aug 2010 06:57:04 -0400 (EDT)
- References: <i3e5i1$h9o$1@smc.vnet.net>
On Aug 5, 3:59 am, Derivator <salc... at ugr.es> wrote:
> Hi. I need some help. The commands
>
> Format[a[x_]]:=f[x,a];
> Format[a[x_,c]]:=a[x];
> Format[b[x_]]:=f[x,b];
> Format[b[x_,c]]:=b[x];
>
> assign a certain format to the symbols a and b, so that the input
>
> {a[1],a[2,c],b[3],b[4,c]}
>
> yields
>
> {f[1,a],f[2,a],f[3,b],f[4,b]}
>
> Now I want to do the same thing for several symbols a,b,.... all at
> once.
> I have tried
>
> list={a,b};
> Do[
> Format[z[x_]]:=f[x,z];
> Format[z[x_,c]]:=z[x];
> ,{z,list}];
>
> but it does not work. The input
>
> {a[1],a[2,c],b[3],b[4,c]}
>
> yields
>
> {f[1,z],z[2],f[3,z],z[4]}
>
> Likewise the following also fails:
>
> list={a,b};
> Format[z_[x_]]:=f[x,z]/;MemberQ[list,z];
> Format[z[x_,c]]:=z[x]/;MemberQ[list,z];
>
> Any suggestions?
> Thanks in advance
>
> L.L.
list = {a,b};
Scan[(Format[#[x_] ] := f[x,#];
Format[#[x_,c]] := #[x] )&,list]
{a[1],a[2,c],b[3],b[4,c]}
{f[1,a],f[2,a],f[3,b],f[4,b]}