Mathematica 9 is now available
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: [mg111587] Re: Format
  • From: Chris <chris.leibs at gmail.com>
  • Date: Fri, 6 Aug 2010 06:58:01 -0400 (EDT)
  • References: <i3e5i1$h9o$1@smc.vnet.net>

On Aug 5, 4: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.

Hey,

I think this may do the trick, but I'm not exactly sure what you are
trying to do. Please post again if this doesn't help.

FuncNames = {a, b};
ToExpression[
    "Format[" <> ToString[#] <> "[x_]]:=f[x," <> ToString[#] <> "];"
     <> "Format[" <> ToString[#] <> "[x_,c]]:=" <> ToString[#] <>
     "[x];"
    ] & /@ FuncNames;
{a[1], a[2, c], b[3], b[4, c]}


  • Prev by Date: Re: Disable " symbol
  • Next by Date: Re: Save a notebook state
  • Previous by thread: Re: Format
  • Next by thread: Re: Format