Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg61807] Re: Question regarding Mathematica's treatment of whitespace
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Mon, 31 Oct 2005 01:17:02 -0500 (EST)
  • References: <dk1k2g$9p9$1@smc.vnet.net>
  • 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
> 
Hello,

I think this strange result is caused by the fact that Mathematica will 
treat a cell consisting of several lines as distinct inputs to 
Mathematica UNLESS it finds certain pieces of syntax, such as open 
brackets or binary operators requiring an RHS, that indicate otherwise.

Try executing the following 2-line cell:

2
3

The answer comes back as 3, because 2 is 'evaluated' and the result 
discarded, and then 3 is 'evaluated'.

However, either of the following cells evaluate as one expression:
(
2
3
)

or

2*
3



Thus the following cell evaluates successfully as one expression:

(
Sin
[Pi]
)

So if you typically write your code inside Module/Block this will not be 
a problem.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: SymbolName question
  • Next by Date: Re: Multicore Calculations
  • Previous by thread: Re: Re: Question regarding Mathematica's treatment of whitespace
  • Next by thread: http://www.mathematica-users.org off-line?