Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2014

[Date Index] [Thread Index] [Author Index]

Search the Archive

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.



  • Prev by Date: Re: How Can I Change the Appearance of a Locator in Manipulate
  • Next by Date: Re: How Can I Change the Appearance of a Locator in Manipulate
  • Previous by thread: Re: Default value in pattern matching
  • Next by thread: compensated summation in norm