MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Question regarding Mathematica's treatment of whitespace

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61808] Re: Question regarding Mathematica's treatment of whitespace
  • From: "Steven T. Hatton" <hattons at globalsymmetry.com>
  • Date: Mon, 31 Oct 2005 01:17:03 -0500 (EST)
  • References: <200510300443.AAA09795@smc.vnet.net> <dk28rb$e6u$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Chris Chiasson wrote:

> I don't know how to do it, but it may be easier to change the way that
> the Mathematicia Front End automatically indents/spaces code to your
> "one true braces form" (to quote Joel Spolsky without looking up the
> real quotation...)

The rule Mathematica uses to determine if input is terminated by and end of
line marker, which I suspect is '\n', is whether the line constitutes a
syntactically complete expression myFunction[x_]:=Module\n does constitute
such an expression.  This may not seem intuitive to people accustomed to
strongly typed and highly structured languages such as C or C++.  One
alternative is to use 
myFunction[xx_]:=
Module[
  {
    x=xx;
  }.
   DoSomething[x]
]

I really wish there were better syntax highlighting, particularly with
parentheses.  Trying to sort out where things begin and end in deeply
nested boxes can be maddening. Forget for the moment that Mathematica
doesn't provide the named entity references in MathML when you copy from a
cell, and consider who much easier it is to find the ends of nesting
component in the following (admittedly verbose) representation:

<math xmlns='http://www.w3.org/1998/Math/MathML'>
 <mn>5) </mn>
</math>
<math xmlns='http://www.w3.org/1998/Math/MathML'>
 <mrow>
  <mrow>
   <mi>M</mi>
   <mtext> </mtext>
   <mo>&#8834;</mo>
   <mtext> </mtext>
   <mi>&#8469;</mi>
  </mrow>
  <mtext> </mtext>
  <mo>&#8717;</mo>
  <mtext> </mtext>
  <mrow>
   <mrow>
    <mn>0</mn>
    <mtext> </mtext>
    <mo>&#8712;</mo>
    <mtext> </mtext>
    <mi>M</mi>
   </mrow>
   <mtext> </mtext>
   <mo>&#8743;</mo>
   <mtext> </mtext>
   <mrow>
    <mo>(</mo>
    <mrow>
     <mrow>
      <mi>m</mi>
      <mo>&#8712;</mo>
      <mi>M</mi>
     </mrow>
     <mtext> </mtext>
     <mo>&#62755;</mo>
     <mtext> </mtext>
     <mrow>
      <msup>
       <mi>m</mi>
       <mo>&#8242;</mo>
      </msup>
      <mo>&#8712;</mo>
     </mrow>
    </mrow>
    <mo>)</mo>
   </mrow>
  </mrow>
 </mrow>
</math>


Put that in your FrontEnd and `C-E' the cell (IOW, Ctrl+Shift-e).  It often
happens that Mathematica doesn't correctly format expressions similar to
this, and I am forced to go in an untangle it.  That is not my idea of fun.
-- 
"Philosophy is written in this grand book, The Universe. ... But the book
cannot be understood unless one first learns to comprehend the language...
in which it is written. It is written in the language of mathematics, ...;
without which wanders about in a dark labyrinth."   The Lion of Gaul


  • Prev by Date: Re: this is ridiculous...
  • Next by Date: preserving order of eigenvalues in a matrix diagonalization
  • Previous by thread: Re: Question regarding Mathematica's treatment of whitespace
  • Next by thread: Re: Re: Question regarding Mathematica's treatment of whitespace