Skip to main content
added 67 characters in body
Source Link
Sjoerd C. de Vries
  • 66.4k
  • 15
  • 192
  • 337

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:

  • YouOn 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 Off somewhere

You might try on(on your Mac systemMMA) the following and see whether it generates an error message (it should):

Message[StringReplace::strse] 

My feeling is that your Windows system is performing like it should. 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:

  • 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 Off somewhere

You might try on your Mac system the following and see whether it generates an error message (it should):

Message[StringReplace::strse] 

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 Off somewhere

You might try (on your Mac MMA) the following and see whether it generates an error message (it should):

Message[StringReplace::strse] 
Source Link
Sjoerd C. de Vries
  • 66.4k
  • 15
  • 192
  • 337

My feeling is that your Windows system is performing like it should. 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:

  • 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 Off somewhere

You might try on your Mac system the following and see whether it generates an error message (it should):

Message[StringReplace::strse]