Re: Default value in pattern matching
- To: mathgroup at smc.vnet.net
- Subject: [mg132276] Re: Default value in pattern matching
- From: Yi Wang <tririverwangyi at gmail.com>
- Date: Tue, 28 Jan 2014 06:17:03 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- Delivered-to: l-mathgroup@wolfram.com
- Delivered-to: mathgroup-outx@smc.vnet.net
- Delivered-to: mathgroup-newsendx@smc.vnet.net
- References: <lbdjjl$58f$1@smc.vnet.net>
Actually, the property I looked after is not that Plus has a default value (though it is an insignificant part of the story), but that Plus has attribute OneIdentity, which affects pattern matching.
SetAttributes[myPlus, OneIdentity]
Default[myPlus] = 0;
a /. {myPlus[a, b_.] -> "matched"}
Out[] = "matched"
The example given here is not exactly as the one in my question. But this is enough for my purpose.