Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #16436

Default value in pattern matching

From Yi Wang <tririverwangyi@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Default value in pattern matching
Date 2014-01-18 10:04 +0000
Message-ID <lbdjjl$58f$1@smc.vnet.net> (permalink)
Organization Time-Warner Telecom

Show all headers | View raw


Hello,

I was investigating the usage of the "a_." pattern. I understand that for some built-in functions with default value, we can do

In[] := a /. {a + b_. -> "matched"}

Out[] = "matched"

However, if I define a function myself with 

In[] := Default[myPlus] = 0;
        myPlus[0] := 0;
        a /. {a + myPlus[b_.] -> "matched"}

Out[] = a

In other words, my default value is not used in the "b_." pattern. Is there a way to get a /. {a + myPlus[b_.] -> "matched"} match in the same way as a /. {a + b_. -> "matched"}?

Otherwise I have to write separately as

In[] := a /. {a -> "matched", a + myPlus[b_] -> "matched"}

This is a lot of additional work for complicated cases.

Back to comp.soft-sys.math.mathematica | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Default value in pattern matching Yi Wang <tririverwangyi@gmail.com> - 2014-01-18 10:04 +0000
  Re: Default value in pattern matching Yi Wang <tririverwangyi@gmail.com> - 2014-01-28 11:05 +0000

csiph-web