Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Taking either a sequence or a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63097] Re: Taking either a sequence or a list
  • From: bghiggins at ucdavis.edu
  • Date: Wed, 14 Dec 2005 04:35:59 -0500 (EST)
  • References: <dnm29m$89q$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Trevor,

Use Alternatives in your pattern, and slightly modify the RHS (replace
L with {L})

Foo3[L___Integer | { L___Integer}] := StringJoin["* * * ",
ToString[Length[{
    L}]], " * * * "];

Cheers,

Brian

Trevor Baca wrote:
> I somtimes SetDelay expressions twice, as in
>
>   Foo[L:{___Integer}] := StringJoin["* * * ", ToString[Length[L]], " *
> * * "];
>   Foo[n___Integer] := Foo[{n}];
>
> reason being that I can then equivalently call either
>
>   Foo[{1, 2, 3, 4, 5}]
>   Foo[1, 2, 3, 4, 5]
>
> and not have to worry about whether Foo[ ] takes a string or sequence
> as argument. (StringJoin[ ] works the same way, which is where I grew
> to like the idea.)
>
> Question: is there a better way to accomplish this type of setting up
> both a list-based and sequence-based interface to an expression, other
> than twice calling SetDelay explicitly (perhaps by cleverly using
> SetAttributes[ ])?
> 
> Trevor.


  • Prev by Date: Re: Remote Mathematica kernels and SSH password
  • Next by Date: Re: Remote Mathematica kernels and SSH password
  • Previous by thread: Taking either a sequence or a list
  • Next by thread: Re: Taking either a sequence or a list