MathGroup Archive 2005

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

Search the Archive

Taking either a sequence or a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63068] Taking either a sequence or a list
  • From: "Trevor Baca" <trevorbaca at gmail.com>
  • Date: Tue, 13 Dec 2005 03:40:50 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

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: PDF/Illustrator Oddity
  • Next by Date: Re: How to compute this sum?
  • Previous by thread: Re: PDF/Illustrator Oddity
  • Next by thread: Re: Taking either a sequence or a list