Question about mathematics commands

  • Thread starter Thread starter raymound
  • Start date Start date
  • Tags Tags
    Mathematics
AI Thread Summary
In Mathematica, comments are created using the syntax (* comment here *), which allows for inline comments, unlike PHP or Fortran where different symbols are used for line comments. For example, in Mathematica, you can comment out a part of a line, such as a = b + c (* + d *) + e, resulting in the expression evaluating to a = b + c + e. If you want to comment out larger sections, you can separate the content into different cells and change their properties to text or section types, preventing evaluation. Additionally, there is a suggestion to define a custom operator using an unused character to create a non-evaluating function, although this approach may not be practical or advisable.
raymound
Messages
13
Reaction score
0
hi
I was going to ask if there's a way to command mathematica not to run a sentence or a part of a sentence as "//" works in php and "!" in fortran
 
Physics news on Phys.org
You mean comment out a line?

(* This is a Mathematica comment *)
 
yes,
is that the only way
isn't there any syntax like the ones in fortran or php?
 
I don't think I follow...

This is a command // remove this bit in PHP (or C++)
This is a command ! remove this bit in Fortran
This is a command (* remove this bit in Mathematica *)
This is a command /* remove this bit in C */

The start and end braces mean you can have it mid-line, whereas the // and ! assume you mean 'comment out to the end of the line'.

a = b + c (* + d *) + e

will give you a = b + c + e
 
thanks
 
If the material you want to comment out is in a separate cell, or you position the cursor and divide the cell with <shift><ctrl>d to put the material in a separate cell, then you change the cell properties and make that a text cell or a Section cell or a SubSection cell or any other kind of cell that isn't evaluated.

Later you can merge the cells back together by selecting the desired cells and merging with <shift><ctrl>m

This would not be appropriate for some things.

Or... something perhaps much less appropriate. What if you picked one of the otherwise unused characters, defined it to be an operator, which is really just a function, set the attributes so that it would not evaluate any arguments and had the operator return Null. I am not certain all this could be done or that this would be a good idea.
 

Similar threads

Replies
4
Views
2K
Replies
1
Views
1K
Replies
9
Views
3K
Replies
2
Views
2K
Replies
2
Views
2K
Replies
2
Views
3K
Back
Top