Preventing “Plus” from rearranging things

偶尔善良 提交于 2019-11-29 07:19:04

The trick to formatting something like myPlus to look like Plus on output is to use Format. Here's a simple example to get you started:

Format[myPlus[expr__]] := Row[Riffle[{expr}, "+"]]

Then, what you will see visually in the notebook is:

In[7]:= x = myPlus[3, 2, 1]
Out[7]= 3+2+1

... but x will still have head myPlus.

Here is a tutorial from the documentation that goes into more details about formatting output, operator precedence, etc.

Hope that helps!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!