MathGroup Archive 2005

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

Search the Archive

Default argument and conditional pattern question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg61796] Default argument and conditional pattern question
  • From: "Matt" <anonmous69 at netscape.net>
  • Date: Sun, 30 Oct 2005 00:43:28 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,
  This works (I want the second argument (if supplied) to be a list of
length 1 and a depth of 2 (meaning no sublist), and if it is not
supplied, I want the default value to be {1})

callLevelAndPrintResults[list_List, lev : (_List?(Length[#] == 1 &&
Depth[#] == 2 &)) : {1}] := Module[some stuff]

Using the /; conditional construct, I could not get default values and
a condition to work together.  So, for example, this works:

callLevelAndPrintResults[list_List, lev_List /; Length[lev] == 1] :=
Module[some stuff]

but I couldn't figure out the syntax to get something like this to
work:

callLevelAndPrintResults[list_List, lev:(_List /; Length[lev] ==
1):{1}] := Module[some stuff]

I know it's mere semantics, but I'm trying to figure out what I can,
and cannot do with these types of things.

Thanks,

Matt


  • Prev by Date: Re: ShowGraphArray
  • Next by Date: SymbolName question
  • Previous by thread: Re: http://www.mathematica-users.org off-line?
  • Next by thread: Re: Default argument and conditional pattern question