MathGroup Archive 2010

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

Search the Archive

Re: Syntax coloring

  • To: mathgroup at smc.vnet.net
  • Subject: [mg111858] Re: Syntax coloring
  • From: Helen Read <hpr at together.net>
  • Date: Sun, 15 Aug 2010 07:39:45 -0400 (EDT)
  • References: <i45rg8$g4s$1@smc.vnet.net>
  • Reply-to: HPR <read at math.uvm.edu>

On 8/14/2010 6:34 AM, Bill Rowe wrote:
> On 8/13/10 at 6:58 AM, tmatsoukas at me.com (Themis Matsoukas) wrote:
>
>> If[a>  1,
>> Do[Print[i], {i, 1, 10}]; (*end do*)
>> ];
>
>> then, the semicolon right before the comment (*end do*) turns
>> magenta.
>
> I don't know whether this should be considered a bug or not. But
> you are using semicolons in places where they have no effect.
>
> A semicolon is used to create a compound expression. When you
> write expr; you are actually creating the compound expression
> expr;Null. And since Mathematica returns the result of the last
> expression in a compound expression, the syntax expr; returns Null.
>
> Now, Do returns Null. So
>
> Do[Print[i] ,{i, 1,10}];
>
> is exactly equivalent in all respects to
>
> Do[Print[i], {i, 1,10]
>
> So, your second If could have been written
>
> If[a>  1, Do[Print[i], {i, 1,10] (*end do*)];
>
> which does not have a syntax coloring issue.

I don't think this is any kind of a bug, but simply a choice on the part 
of WRI. When I am writing a complicated compound expression, I 
habitually slap a semi-colon and a line-break at the end of each piece 
of it, which I find helps readability.  I am not even thinking about 
whether I'm at the last line or not, and it gets a semi-colon too. I 
might be trying out parts of it, and then go back and add more to it, 
and I like the semi-colon to already be there on the (formerly) last 
line when I go back and edit.

That last semi-colon isn't strictly necessary, and the syntax coloring 
flags it red. But it doesn't hurt anything to keep that last semi-colon, 
and as long as one realizes that, you can just ignore it.

-- 
Helen Read
University of Vermont


  • Prev by Date: Re: Problem with using Symbol[] in a loop
  • Next by Date: Re: Set and Unevaluated
  • Previous by thread: Syntax coloring
  • Next by thread: Re: Syntax coloring