Bug introduced in 9.0 or earlier and persisting through 11.1
First off:
$Version
(* "11.0.0 for Microsoft Windows (64-bit) (July 28, 2016)" *)
$CharacterEncoding
(* "WindowsANSI" *)
I would like to use an unused operator to define a binary function, e.g ± or ·, as these are part of the Windows ANSI code page (i.e. Windows-1252). Doing this in a Mathematica notebook is all well and good, but if I try to do it in a source file that I feed to wolfram -script ..., the parser acts up:
a_±b_:={a+b,a-b}
Print[5±3]
SetDelayed::write: Tag Times in _ (a_±b) is Protected.
So it seems this gets parsed as two tokens a_±b (i.e. a pattern named a with head ±b, which is not a thing) and _. If I insert a space in front of the ±, everything works fine:
a_ ±b_:={a+b,a-b}
Print[5±3]
{8, 2}
I'm seeing the exact same behaviour with ·.
Is there a good reason why the first version isn't parsed correctly or is this a bug?
.mfiles, otherwise they will not be portable between platforms. I learned this the hard way. You could use\[PlusMinus]instead. Related: https://mathematica.stackexchange.com/q/144902/12 (I know that this is not an answer.) – Szabolcs May 17 '17 at 09:24\[PlusMinus]I'd rather go back to defining a simple function because I find this ASCII longhand notation very unreadable. – Martin Ender May 17 '17 at 09:25±. But it encodes this as\[PlusMinus]. This is comparable to how UTF-8 encodes some characters on 4 bytes instead of 1. But this probably won't be bought by whoever judges your code golf. – Szabolcs May 17 '17 at 09:535±3, no spaces. What doesPrint@Head[5±3]output when you put it in a script? – Szabolcs May 17 '17 at 09:55Print@Head[a_±b_], which printsTimeswhen there are no spaces. Definitely a bug to be reported. – Szabolcs May 17 '17 at 09:56a_±b_is misparsed.5±3is fine. – Szabolcs May 17 '17 at 10:12