Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Format

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111603] Re: Format
  • From: Derivator <salcedo at ugr.es>
  • Date: Sat, 7 Aug 2010 01:31:14 -0400 (EDT)
  • References: <i3e5i1$h9o$1@smc.vnet.net> <i3gppn$2vo$1@smc.vnet.net>

On 6 ago, 12:56, Ray Koopman <koop... at sfu.ca> wrote:
> 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]}

The two solutions (this one with Scan and the other with ToExpression)
work perfectly. Thank you.


  • Prev by Date: Programming / Design question
  • Next by Date: > classroom combinatorics
  • Previous by thread: Re: Format
  • Next by thread: how to work with custom probability distributions