Message Boards Message Boards

0
|
2869 Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Help redefining the output suppression key ";"

Posted 3 years ago

Hello,

As I'm sure almost everyone here knows, the semicolon can be used to suppress automatic output from an input cell. An example is shown below.

In[1]    number = 5 + 5 

Out[1]    10

vs

In[2]    number = 5 + 5;

Out[2]

Now buried somewhere in Mathematica's system files I'm assuming there's a file that says something along the lines of "When evaluating an input cell, if ";" is present, Output -> False"

Is anyone able to tell me what the PATH to that file is? Or suggest the most probable PATH to that file? I'm using Mathematica 12.2.0 on MacOS Catalina.

The reason I ask is because I currently have the semicolon set up to do something much more important than suppressing output, but I'd still like to be able to suppress output as it is quite useful, so I'd like to find the PATH to the file where the output suppression keybinding is defined.

POSTED BY: Isaac Avery
4 Replies
Posted 3 years ago

Could you possibly give an example of how I would go about evaluating an expression to Null?

Yeah, use CompoundExpression where the last element is Null:

CompoundExpression[
    data = {1,3,6,5,3,3,6},
    Print["Median: ", Median[data]],
    Null
]

You're talking about using ; for something else, which I don't want to know anything about because it sounds pretty shady, so I used the explicit function call version of CompoundExpression.

Or alternatively, can you tell me which system file assigns the semicolon to be that infix operator shortcut that you described?

This is not a thing. This behavior is compiled into the WL language interpreter for how it responds to an EnterExpressionPacket (the MathLink/WSTP packet type that handles the In[1] read-eval-print loop). In other words, like most of the system it's not available in source form in the product.

POSTED BY: Joel Klein
Posted 3 years ago

Ok I see.

Well thank you for the information and help on how to implement the Null output using the CompoundExpression.

POSTED BY: Isaac Avery
Posted 3 years ago

Actually, any expression evaluating to Null will result in no Output cell being created.

If you look at FullForm[Hold[expr;]] you'll see this as CompoundExpression[expr, Null]. In other words, semicolon (;) is actually an infix operator for CompoundExpression, and if you don't provide an expression on its right side, a Null is substituted, and voila, no output.

So, to suppress output, evaluate to Null.

POSTED BY: Joel Klein
Posted 3 years ago

Thanks, that's so interesting.

Could you possibly give an example of how I would go about evaluating an expression to Null?

I'm not very good with the Wolfram syntax, so for example if my expression was

n = 2

How could I evaluate that cell and not get any output printed?

Or alternatively, can you tell me which system file assigns the semicolon to be that infix operator shortcut that you described?

POSTED BY: Isaac Avery
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract