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: Returning an empty sequence

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63293] Re: Returning an empty sequence
  • From: dh <dh at metrohm.ch>
  • Date: Fri, 23 Dec 2005 05:08:20 -0500 (EST)
  • References: <dode3g$62d$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Trevor,
you must prevent "Sequence[]" to be evaluated before Switch is called. 
This can be done by "Unevaluated":

f[n_] := Switch[n,
       1, "foo",
       2, Unevaluated[Sequence[]],
       3, {"bar"}];

Daniel


Trevor Baca wrote:
> What's the right way to have an expression evaluate to an empty
> sequence?
> 
> I'd like ...
> 
> f[n_] :=
>   Switch[n,
>     1, "foo",
>     2, Sequence[ ],
>     3, {"bar"}];
> 
> ... to work, but instead I get the message
> 
> Switch::"argct": "Switch called with 6 arguments. Switch must be called
> with an odd number of arguments."
> 
> meaning that the Sequence[ ] is flattened in the rhs definition of f[
> ].
> 
> Is there a way to get f[ ] to evaluate to the empty Sequence[ ] (rather
> than Null)?
> 
> Trevor.
> 


  • Prev by Date: RE: Returning an empty sequence
  • Next by Date: Adding matrices for use in NDSolve input
  • Previous by thread: RE: Returning an empty sequence
  • Next by thread: Re: Returning an empty sequence