As already explained, this happens because MatrixForm
act as a wrapper.
The answer to the question about how this behavior is implemented and how can eventually be reproduced is contained in the Informmation
of the system symbol $OutputForms
. Indeed
?? $OutputForms
returns:
$OutputForms is a list of the formatting functions that get stripped
off when wrapped around the output.
and
$OutputForms={InputForm,OutputForm,TextForm,CForm,Short,Shallow,MatrixForm,TableForm,TreeForm,FullForm,NumberForm,EngineeringForm,ScientificForm,QuantityForm,PaddedForm,AccountingForm,BaseForm,DisplayForm,StyleForm,FortranForm,ScriptForm,MathMLForm,TeXForm,StandardForm,TraditionalForm}
As noted earlier, this affects what the kernel stores in the output history when it encounter a result with any of the previous Head
.
For example:
Unprotect[$OutputForms];
AppendTo[$OutputForms, foo];
foo[1]
Head[%]
foo[1]
Integer
I discovered this last summer while working on a way to better show rational matrices: if interested please see this question. I ended up writing my own PrettyMatrixForm
with the same output behavior as one of the previous XyzForm
.
Out
is special. Here's another special case:1;
clearly evaluates toNull
yet the value assigned to the correspondingOut
expression will be1
. A related question would be: how can we create our own function or wrapper that influences that value assigned toOut
? $\endgroup$mat//MatrixForm;
nowOut
gets assigned theMatrixForm
. $\endgroup$1;
I find especially troubling! Compare the behavior of that with that ofa; b
which has outputb
and then%
also givesb
. So why doesn't1;
then%
give either nothing or elseNull
? $\endgroup$1;
as1;Null
. Well, I guess this is a useful feature but a bit weird. I learned about it on MathGroup. I was also very surprised. $\endgroup$