I wrote a notebook on Mac OS 10.7.4 and run it on Windows XP at work. On my Mac I use a full version of Mathematia 8.0.1.0, whereas on the Windows-system only a trial version (Version 8.0.4.0.).
First of all I cannot run the following code on the Windows system (on Mac it works perfect):
ImportData={{"Test1", 5670.`, 0.`, 180.`, 2756.`, 2443.`, 180.`, 1008.`, 2007.`},
{"Test2", 100.`, 0.`, 3006.`, 1235.`, 9874.`, 4543.`, 3241.`, 5004.`}};
WhitespaceCleaning[string_] :=
StringReplace[
string, (StartOfString ~~ Whitespace) | (Whitespace ~~
EndOfString) :> ""]
OriginalData =
Drop[ImportData, 1] /. {a_, b_, cc_, d_, e_, f_, g_, h_, i_} ->
{WhitespaceCleaning@a, {b, cc, d, e, f, g, h, i}};
However I can get the same result as on my Mac with the following code for my Windows system:
allData=ImportData;
numData=allData[[All,2;;]]
strings0=allData[[All,1]];
stringsWOSpacing=WhitespaceCleaning/@strings0;
OriginalData=Transpose[{stringsWOSpacing,numData}]
The rest of my code runs perfect (I get the same results on both operating systems). However, running my code on Windows provokes many messages (such as Divide::index, Divide::infy, Power::infy, General::stop, Less::nord, LessEqual::nord) which does not happen on my Mac.
I don't understand why Mathematica on my Windows system is acting so odd. Does anyone has an idea?
Answer
My feeling is that your Windows system is performing like it should and that the problem lies with your OS X system. Using the -> instead of :> causes the immediate evaluation of the right hand side of the rule yielding an expression of the form
StringReplace[a, (StartOfString ~~ Whitespace) | (Whitespace ~~ EndOfString) :> ""]
with a still undefined. Since StringReplace expects a string as first argument it balks and generates an error message. It then returns unevaluated. Then the pattern match kicks in, a gets the value "Test2" and evaluation of StringReplace continues, now with the sting "Test2" as argument which works.
In this case the :> is the better choice.
The question should be: why doesn't your Mac version object like the Windows version does (and not the other way around)?
I see a number of options:
- On your Mac version you have set error messages preferences (Edit > Preferences > Evaluation> Message and Warning action) to not print to the input notebook
- You have switched off error messages using
Offsomewhere
You might try (on your Mac MMA) the following and see whether it generates an error message (it should):
Message[StringReplace::strse]
Comments
Post a Comment