Re: Function & Format
- To: mathgroup at smc.vnet.net
- Subject: [mg5107] Re: Function & Format
- From: "David B. Wagner" <dbwagner at princon.com>
- Date: Wed, 30 Oct 1996 22:04:04 -0500
- Organization: Principia Consulting
- Sender: owner-wri-mathgroup at wolfram.com
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 !)
> In:= fun[x_]:= x^2
> In:= fun
> Out= -FUN-
> In:= %+1
> Out= 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:
Next by Date:
Removing In and Out
Previous by thread:
Function & Format
Next by thread: