Question about mathematics commands

  • Thread starter Thread starter raymound
  • Start date Start date
  • Tags Tags
    Mathematics
Click For Summary

Discussion Overview

The discussion revolves around how to comment out parts of code in Mathematica, exploring different methods and syntax for achieving this, including comparisons to other programming languages like PHP and Fortran. The scope includes technical explanations and practical usage within Mathematica.

Discussion Character

  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant inquires about a command in Mathematica to comment out a sentence or part of a sentence, similar to syntax in PHP and Fortran.
  • Another participant confirms that the syntax for comments in Mathematica is to use (* ... *), but questions if there are other methods available.
  • A further reply explains the difference between comment styles in various languages, highlighting that Mathematica's comment syntax allows for mid-line comments, unlike the others mentioned.
  • Another participant suggests an alternative approach involving separating code into different cells and changing cell properties to prevent evaluation, while also proposing a more unconventional method of defining an unused character as a non-evaluating operator, though expressing uncertainty about its feasibility and appropriateness.

Areas of Agreement / Disagreement

Participants generally agree on the use of the standard comment syntax in Mathematica, but there is uncertainty regarding alternative methods and their appropriateness, indicating that multiple views remain on the best approach.

Contextual Notes

The discussion does not resolve whether the unconventional method of defining an unused character as a non-evaluating operator is practical or advisable, leaving this as an open question.

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 21 ·
Replies
21
Views
6K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
3K
Replies
7
Views
3K