pattern bugs and comment on intuitive syntax for the New Year
- To: mathgroup at smc.vnet.net
- Subject: [mg115143] pattern bugs and comment on intuitive syntax for the New Year
- From: Richard Fateman <fateman at cs.berkeley.edu>
- Date: Sun, 2 Jan 2011 04:56:08 -0500 (EST)
Guess the results.
x+3 /. x+c___ -> aha[c]
x /. x+c___ -> aha[c]
x /. x+c___:0 -> aha[c]
compare to
x+y+3 /. x+y+c___ -> aha[c]
x+y /. x+y+c___ -> aha[c]
x+y /. x+y+c___:0 -> aha[c]
x+y+a+b /. x+y+c___ :> aha[c]
x+y+a+b /. x+y+c___ :> aha[Plus[c]]
x+y /. x+y+c___ :> aha[Plus[c]]
I think the requirement for the :0 represents a bug. Maybe the
need for the Plus[], too. The treatment of NullSequences within
a Flat operator could be different, leaving an operator around.
............
Another item. really, syntax.
define
GreaterThan[q_]:= #>q&
gt2=GreaterThan[2] (* a function of one argument.
is that argument > 2? *)
mm[2, 10] /. mm[q_, s_?GreaterThan[q]] :> aha[q, s]
doesn't give aha..
mm[2, 10] /. mm[q_, s_?gt2] :> aha[q, s]
does give aha
this works, though.
mm[2, 10] /. mm[q_, s_?(GreaterThan[q])] :> aha[q, s]
I love that intuitive syntax. None of that excess
parentheses and stuff. (sarcasm)
This error would have been
much more apparent in Lisp.
happy new year.