Re: Strange syntax errors when writing functions ?
- To: mathgroup at smc.vnet.net
- Subject: [mg30997] Re: Strange syntax errors when writing functions ?
- From: "Alan Mason" <swt at austin.rr.com>
- Date: Sat, 29 Sep 2001 20:43:41 -0400 (EDT)
- References: <email@example.com>
- Sender: owner-wri-mathgroup at wolfram.com
Dear Axel, It would help if you gave a specific example and specified the syntax error. You should definitely send your file to Wolfram support. I'm running version 4.1 on Windows 2000 and have encountered similar problems in the past. The culprit seems to be the Front End editor. It sometimes makes mistakes, especially with comments (* ... *). The monitor may show the statement before the comment properly terminated with a semicolon, but the Front End doesn't see it. I get around the problem by adding an extra semicolon to the line preceding the comment. Then the editor "gets the hint", and I can later delete the extra semicolon and all is fine. The problem seems to arise when editing the code on-screen; Mathematica can get confused. Also, sometimes I get a "Times protected" error, or a function returns Null; this usually indicates that I've forgotten to terminate a statement with a semicolon, but sometimes the semicolon is definitely there (I see it on the monitor). Solution: add an extra semicolon-- it's annoying to have to do this, but it doesn't happen often. On the other hand, it gets *really* annoying when you have no idea which part of your code the editor is messing up on, since on screen everything is absolutely correct. It's a bad case of "what you see is not what you have". But Mathematica 4.x still represents a considerable improvement over 3.x. A suggestion for minimizing confusion with comments -- always type (* *) [both parts] first, then fill in the comment body. This helps the editor because the comment is already fully delimited, so it doesn't have to search through the rest of your code block as you type. The fact that the saved corrected version is incorrect when reloaded is strange. Very rarely I get an error on loading a notebook, with a message saying "file may have become corrupted, or was incorrectly generated". I suspect the latter. In this case, if the problem is localized you can edit the ASCII version of the faulty notebook; Mathematica does indicate the starting line number of the bad data. But this will require a knowledge of Mathematica's notebook format. This approach can also rule out a disk problem -- if the file isn't trashed, you can assume Mathematica is at fault. Look at your file using an ASCII editor, do a little experimenting, and you may be able to figure out what is going wrong. You might be able to use the information gained to prevent future occurrences by modifying your code-input habits. (I did this under version 3.01 -- in Print[ "x is ", x] statements, always leave a space after the opening [; this is not necessary in later versions.) I don't know why the Front End editor/parser still has bugs; at this late stage in Mathematica's development, one would certainly expect something as basic as keyboard-to-screen-to-file correspondence to be rock solid. But Mathematica is a strange, even uncanny beast, and the Front End is doing a lot of nontrivial work. As for features, it would be nice if Mathematica would let you indent statements better, especially since its syntax for If, For, etc., doesn't lend itself to readably structured block programming, the crucial distinction between commas and semicolons being far too hard on the eye whereas indentation is obvious. The quirky editor doesn't handle white space well and it sometimes insists on inserting odd line breaks that I can't get rid of. Mathematica's practice of using white space to represent Times (e.g., x y means Times[x, y]) is a great convenience for the user but also has a price -- it makes parsing more difficult, and some of the perverseness and bugs in the Front End may stem from this. A quibble: with subscripts the normal (forward) delete doesn't work right, but backspace-delete does. And another: when pasting rules that involve subscripts, Subscript appears as a string (in quotation marks which you'll need to remove). Oh well... we should appreciate Mathematica for what it alone has to offer. Alan "Axel Kowald" <axel at itb.biologie.hu-berlin.de> wrote in message news:9p2pt0$313$1 at smc.vnet.net... > Hello everybody, > > I'm using Mathematica 4.0 under winNT and from time to time I have a problem > with Mathematica which drives me crazy. I wonder if anybody has experienced the > same problem. > > Sometimes, if I write a function and press shift enter Mathematica complains > that there is a syntax error. I can't find one and copy line for line to > a new location until I copied the whole function. If I now press shift > enter it works, although nothing has changed !!! > > While this is annoying, today it got worse. I had the same problem and > solved it by copying. But this time saving the file brought back the old > error message :-( That means, after I corrected the problem, saved the > file, exited Mathematica, started it again and loaded the file, Mathematica again > complains about a syntax error. > > Does anyone know about the problem and knows a solution ? > > Many thanks in advance, > > Axel Kowald > > > > > -- > ----------------------------------------------------------------- > Dr. A. Kowald > Innovationskolleg Theoretische Biologie > Humboldt University Berlin > Invalidenstr. 43 > 10115 Berlin > Germany > > Email: a.kowald at itb.biologie.hu-berlin.de > http://itb.biologie.hu-berlin.de/~axel > Phone: +49 30 2093 9105 > Fax: +49 30 2093 8801 > ----------------------------------------------------------------- >