Re: confusing Mathematica?

*To*: mathgroup at smc.vnet.net*Subject*: [mg30616] Re: [mg30262] confusing Mathematica?*From*: "Michael" <michael at science.edu>*Date*: Fri, 31 Aug 2001 04:09:41 -0400 (EDT)*References*: <200108040514.BAA18802@smc.vnet.net> <3B6D9E96.D55CA6AF@wolfram.com>*Sender*: owner-wri-mathgroup at wolfram.com

----- Original Message ----- From: "Daniel Lichtblau" <danl at wolfram.com> To: mathgroup at smc.vnet.net Subject: [mg30616] Re: [mg30262] confusing Mathematica? > Michael wrote: > > > > I've got a rather length function consisting of a module within a block > > within a block. Within the module is a while statement containing at a > > particular point an if within a replace within an if. > > > > Upon routine editing I happened to make the following change: > > > > ... > > If[<condition>, > > (* Here I inserted the rest of this line: *) Map[(X)&,vars]; > > (* This comment was already here... *) > > If[<valid stuff here>]; > > , > > > > and suddenly I get a huge syntax error looking something like this... > > > > Syntax::sntxf : > > "If [<<1>>,<<1>>]; cannot be followed by "(code snipped)". > > > > The error is nowhere near where I actually insert the line. The problem is, > > when I delete the line I just added I *still* get an error. The way the > > front end spuriously moves text around while I am trying to complete > > brackets and braces is most unhelpful, and I thought perhaps I had made a > > change somewhere else in the function without realizing it. But after a > > long time trying to figure out where the error is, I ran diff against the > > original function and the function Mathematica doesn't like, and there is no > > difference. > > > > Any ideas what is going on here? Am I confusing Mathematica with so many > > things nested inside each other? > > > > Michael > > I am pretty sure you are describing a problem I used to have. It is an > issue with the comments confusing the parser. At some point I found a > replicable instance in my office and grabbed a front-end developer and > showed it to him. He played with it a bit and we reduced it to the point > where a bug report could be filed. The good news is that so far as I am > aware it is now fixed, though I do not know what version has the fix; > this may not yet be on the market. > > As a workaround, I think things always improve when all the comments are > removed. If, like me, you rely on commenting out sections of code as > part of debugging, this is really inconvenient. If instead your comments > are for explanatory purposes, you can do better using text cells. > > Daniel Lichtblau > Wolfram Research > As an update, there definitely do NOT have to be comments, and in fact the complexity of the expression does not have to be that great. I've encountered a couple of times, one just today, in which I go back and make a simple modification to a function (which has not comments) and have the front end get confused. In this case, the function was only 15 lines long, and the maximum nesting depth was three. The change that confused it was to change ...{s - soff }... to ... {s - soff - StringLength[x]} ... I have found a quick-n-dirty workaround, although it's rather annoying to have to try a workaround when one has to first realize there might really not be the error that is claimed. The fix is to simply select the cell, then hit alt+7 to convert it to text, then alt+9 to convert it back to an input expression. When I do this the error goes away. However the whitespace formatting of the function is lost, this fix does not make the Front End less prone to getting confused. Michael

**References**:**confusing Mathematica?***From:*"Michael" <michael@science.edu>