MathGroup Archive 1995

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

Search the Archive

Re: Formating output of Modules

  • To: mathgroup at smc.vnet.net
  • Subject: [mg2259] Re: [mg2214] Formating output of Modules
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Thu, 19 Oct 1995 01:32:36 -0400

Scott Herod <sherod at boussinesq.colorado.edu>
in [mg2214] Formating output of Modules
asks about formatting output.

Here is his example:

>  Format[spam[x_]] := 1/x;
>  spam[a_] := Module[{},pop = Table[a,{3}]];
>  spam[8]
>
>     {8, 8, 8}
>
> I would like spam[8] to return {8,8,8} but to print the output as 
> 1/8.
"

Scott,
The output is {8,8,8} which is not of the form spam[x_]; so no  
formatting is done. Also,to get 1/8 needs a different formatting  
rule.

It seems unlikely that you want to change the format for lists, so  
you might consider wrapping the output and then putting in a  
formatting instruction for the wrapped form.

* Example *

  Format[vv[{x_,___}]] := 1/x;
  spam[a_] := Module[{},pop = vv[Table[a,{3}]]];
  spam[8]

       1
       -
       8

   FullForm[%]

      vv[List[8, 8, 8]]

Allan Hayes
hay at haystack.demon.co.uk


***********************************

Begin forwarded message:

>From: Scott Herod <sherod at boussinesq.colorado.edu>
>To: mathgroup at smc.vnet.net
>Subject: [mg2214] Formating output of Modules
>Organization: University of Colorado at Boulder

I've got an annoying little problem that I was hoping someone can
help me solve.  I have a Module, NDelaySolve, which returns a
numerical approximation of solutions to differential-delay equations.
In order to make the output look as much like that of NDSolve as
possible, I have the module return something like

{{x[t] -> g[t], y[t] -> f[t]}}

where g[t] and f[t] are often big Which[] functions.  I would like
to reduce the output by creating a DelaySolveFunction[][t] which
looks something like an Interpolating function.

Here is an example:

In[4]:=
  Format[spam[x_]] := 1/x;
In[8]:=
  spam[a_] := Module[{},
    pop = Table[a,{3}]
  ];
In[9]:=
  spam[8]
Out[9]=
  {8, 8, 8}


This Format isn't doing what I want.  I would like spam[8] to  
return {8,8,8}
but to print the output as 1/8.  If I get this one to work, I could solve
my real problem.

Scott Herod
sherod at newton.colorado.edu



  • Prev by Date: FW: RE: Mathlink & Graphics....
  • Next by Date: Re: using accents in graphs?
  • Previous by thread: Re: Formating output of Modules
  • Next by thread: Windows-based Notebook to HTML Convertor