Re: Patterns and default arguments
- To: mathgroup at smc.vnet.net
- Subject: [mg28137] Re: Patterns and default arguments
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sun, 1 Apr 2001 00:08:01 -0500 (EST)
- References: <9a438f$cs9@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Jeff: How about the following? f[x1_,x2:(y_/;MatchQ[y,{___Integer}]):{}]:={x1,x2} f[3] {3,{}} f[3,2] f[3,2] f[3,{1.2}] f[3,{1.2}] f[3,{1,2}] {3,{1,2}} -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "Jeff DuMonthier" <jeff at lheapop.gsfc.nasa.gov> wrote in message news:9a438f$cs9 at smc.vnet.net... > I am trying to combine a pattern with a default argument in a delayed > set expression and it is not working. > > I can make a default argument work like this: f[x1_, x2_List:{}]:=... > > And the pattern works like this: f[x1_, x2:{_Integer...}]:= > > But if I combine the two like this: f[x1_, x2:{_Integer...}:{}]:= > Mathematica accepts it without error and the pattern expression works > but the default does not. > > Am I using the wrong syntax or can the two just not be combined? > > > Also, is there a way to specify a pattern for aguments to something > defined as a function (i.e. 'Function[...]') rather than a delayed set? > I have to use 'Function' or ()& in order for the head to be 'Function' > rather than 'Symbol'. > > -Jeff DuMonthier >