MathGroup Archive 2005

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

Search the Archive

Re: Returning an empty sequence


On 22 Dec 2005, at 14:04, 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.
>

Yes.

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


f[1]


foo


f[2]

Sequence[]

Andrzej Kozlowski


  • Prev by Date: RE: Re: NDSolve
  • Next by Date: Re: Convincing Mathematica that Sqrt[a+b]Sqrt[a-b]==Sqrt[a^2+b^2]
  • Previous by thread: Returning an empty sequence
  • Next by thread: Re: Returning an empty sequence