# Defining output format tutorial : i don't understand what the function Format is really usefull for

I was reading this documentation page : http://reference.wolfram.com/language/tutorial/DefiningOutputFormats.html

I really don't understand the point of the Format function.

Indeed, if I take the second example :

Format[xrep[n_]] := StringJoin[Table["x", {n}]]


Calling xrep would give the exact same result as defining things like :

xrep[n_]:=StringJoin[Table["x", {n}]]


So what does the function Format "add of new" here.

Same for the first example, I could write :

bin[x_, y_] := MatrixForm[{{x}, {y}}]


Instead of :

Format[bin[x_, y_]] := MatrixForm[{{x}, {y}}]


And everything would happen the same.

So I don't get what the Format function allows us to do more ?

## 1 Answer

Format allows you to show expression in a nice form while you are still able to work with them as before. By evaluating to _String/_MatrixForm you lose information/flexibility.

Consider:

bin /: bin[x_, y_]^n_. := bin[x, y^n];
Format[bin[x_, y_]] := Row[{"bin[", Panel[Column@{x, y}], "]"}];

bin[2, 2]^3
%^3 while

bin2 /: bin2[x_, y_]^n_. := bin2[x, y^n];
bin2[x_, y_] := Row[{"bin2[", Panel[Column@{x, y}], "]"}];

bin2[2, 2]^3
% ^3 • Just a fast question before I can understand your answer : what does the "bin /: " does before you define your bin function ? Or at least what is the name of the symbol ? – StarBucK Apr 26 '18 at 9:52
• @StarBucK see TagSetDelayed but if you select it and hit F1 it will take you there. – Kuba Apr 26 '18 at 9:53