Re: Question regarding Mathematica's treatment of whitespace
- To: mathgroup at smc.vnet.net
 - Subject: [mg61845] Re: [mg61795] Question regarding Mathematica's treatment of whitespace
 - From: Igor Antonio <igora at wolf-ram.com>
 - Date: Tue, 1 Nov 2005 00:39:39 -0500 (EST)
 - Organization: Wolfram Research, Inc.
 - References: <200510300443.AAA09795@smc.vnet.net>
 - Reply-to: igora at wolf-ram.com
 - Sender: owner-wri-mathgroup at wolfram.com
 
Matt wrote:
> Hello,
>   It seems that most of the time Mathematica ignores whitespace.  e.g. all of
> the following evaluate with no problem:
> 
> Sin    [
> Pi/2
> ]
> 
> 
> Sin    [
> 
> 
> 
> Pi/2
> 
> 
> 
> ]
> 
> 
> However,
> 
> Sin
> [Pi/2]
> 
> does not.  Is that just the way it is?  The reason I ask, is because I
> would like to be able to use brackets '[,]' as I do braces in C/C++ to
> help show the 'flow' of logic (within larger functions obviously), but
> obviously Module[] doesn't work if it sees a cr/lf before the opening
> bracket.
> 
> Thanks,
> 
> Matt
You're correct that Mathematica ignores most whitespaces, but Mathematica will 
treat different lines as different expressions, unless there are 
brackets/parentheses/curly braces/operators/etc that indicate that the content 
continues on the next line.
Here's a similar example:
In[13]:= 1 +
          1
Out[13]= 2
In[14]:= 1
          +1
Out[14]= 1
Out[15]= 1
You have to have something that indicates the expression is not complete on the 
current line.  In your case, you'll have to use the brackets.  The way I write 
to show the "flow" of logic is:
f[x_] := Module[{},
   ...
]
or sometimes
f[x_] :=
   Module[{},
   ...
]
(if I want the name of the function on its own line)
When "looking" at the code, I can quickly match the closing bracket of Module 
with the function f.
-- 
Igor C. Antonio
Wolfram Research, Inc.
http://www.wolfram.com
To email me personally, remove the dash.