MathGroup Archive 1996

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

Search the Archive

Re: Function & Format

  • To: mathgroup at
  • Subject: [mg5107] Re: Function & Format
  • From: "David B. Wagner" <dbwagner at>
  • Date: Wed, 30 Oct 1996 22:04:04 -0500
  • Organization: Principia Consulting
  • Sender: owner-wri-mathgroup at

F Renard wrote:
> Can anyone tell me how to construct a function that doesn't PRINT
> the real result, but any string instead (like "-Graphics-")
> (If it is possible !)
> Example:
> In[1]:= fun[x_]:= x^2
> In[2]:= fun[3]
> Out[2]= -FUN-
> In[3]:= %+1
> Out[3]= 10
> I don't know if the function Format is useful for that...

You are correct in that this is what Format is used for. However,
in order to use format (realistically), your function needs to return
an answer wrapped in a special head.  For example, all plotting commands
return a graphics object, which has the form Graphics[primitives, options].
A format definition of Format[Graphics[__]] := "-Graphics-" causes any
expression with the head Graphics to print as the string "-Graphics-".
In your example, the only way to get the effect you want is to make a
definition like Format[_Integer] := "-FUN-", which would, of course, cause
ALL integers to print as "-FUN-". Not what you probably want to have happen.

  • Prev by Date: Integration..Constants
  • Next by Date: Removing In[] and Out[]
  • Previous by thread: Function & Format
  • Next by thread: Calculus Wiz