MathGroup Archive 2005

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

Search the Archive

Re: How to create a new Form

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58809] Re: [mg58755] How to create a new Form
  • From: stephen layland <layland at wolfram.com>
  • Date: Tue, 19 Jul 2005 04:10:21 -0400 (EDT)
  • References: <200507170704.DAA02672@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

and thus spake Nilton [2005.07.17 @ 02:16]:
> I would like to create a new Form that is a "wrapper" (like Short,
> CForm, ...), which affects printing, but not evaluation. For example:
> 
> In[1]:= 10 + f[5] // BinaryForm
> 
> Out[1]//BinaryForm =
>         1010 + f[101]
> 
> In[2]:= %
> Out[2]= 10 + f[5]
> 
> I know there is BaseForm, but this is just an example. In fact I would
> like to do something more complicated, but must know how to do
> something like this first.
> 
> Can anyone help?

Try something like this:

    In[1]:= Format[BinaryForm[x_]] := x /. n_?NumberQ :> FromDigits[IntegerDigits[n, 2]]
        Unprotect[$OutputForms]; AppendTo[$OutputForms,BinaryForm];
        Protect[$OutputForms];

    In[4]:= 1234+f[234+x]//BinaryForm

    Out[4]//BinaryForm=
    10011010010+f[11101010+x]

    In[5]:=
    %

    Out[5]=
    1234+f[234+x]


(and I'd recommend avoiding looking at the Combinatorica code. ;) )

Happy Hacking!

> Thanks,
> -- Nilton

--
/*------------------------------*\
|        stephen layland         |
|    Documentation Programmer    |
| http://members.wri.com/layland |
\*------------------------------*/


  • Prev by Date: Functional equations for HermiteH[n,x]
  • Next by Date: Re: Trace[ Through [ (Max - Min) [ {1, 2, 3, 4, 5} ] ] ]
  • Previous by thread: Re: How to create a new Form
  • Next by thread: Re: How to create a new Form