Re: How to create a new Form
- To: mathgroup at smc.vnet.net
- Subject: [mg58820] Re: How to create a new Form
- From: Peter Pein <petsie at dordos.net>
- Date: Tue, 19 Jul 2005 04:10:55 -0400 (EDT)
- References: <dbd114$2sp$1@smc.vnet.net><dbe3q8$d9r$1@smc.vnet.net> <dbflbv$mtn$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Nilton schrieb: > Thanks for the answers, but it's not what I want... :( > > I know I can use BaseForm to do this (as I told), and I know how to use > format to format expression on any Form that is built-in to Mathematica > (like: CForm, FortranForm, InputForm, StandardForm, etc.). This is what > documentation explain. > > What I want to know, is how to create my own "output form". This > BinaryForm is just a simple example, in fact what I want to do is more > complicated (and I tried to simplify the question). > > yehuda: I looked at Combinatorica, but found just a formatting rule for > graphs, and not and example of how to create a new output form. > > Maybe someone from Wolfram staff could help me? > > Thanks, > -- Nilton > > Peter Pein wrote: >> >>Have a look at the documentation (and example) for Format[]: either on >>your hard disk or here: >>http://documents.wolfram.com/mathematica/functions/Format >> >>-- >>Peter Pein >>Berlin >>http://people.freenet.de/Peter_Berlin/ > > Dear Nilton, may I - again - lead your attention to the documentation of Format[]? In the (so called further) example you'll find exactly what you're looking for: http://documents.wolfram.com/mathematica/Built-inFunctions/InputAndOutput/FormatTypes/FurtherExamples/Format.html Another example: Let's assume you want to build a form that shows a list of zeros and ones as a run length encoded form with the first element of the original list as first element and the lengths of the runs of the digis as second element and you want to call it RLEForm. Format[RLEForm[l_]] := {First[l], Length /@ Split[l]} and you can already use it like FullForm and friends: lst = Table[Random[Integer], {10}] lst//RLEForm {1, 1, 0, 1, 1, 0, 0, 0, 1, 0} {1, {2, 1, 2, 3, 1, 1}} And in a similar way you can do this with more complicated conversions: myConv[expr_Integer]:=....a lot of code for integer arguments... myConv[expr_]:=...same for other domains... Format[myFormat[expr_]]:=myConv[expr]; that's it. But maybe I've mistaken your question again - so I'll better shut up before becoming a "pein" in the neck. -- Peter Pein Berlin http://people.freenet.de/Peter_Berlin/