MathGroup Archive 2005

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

Search the Archive

Re: Returning an empty sequence

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63303] Re: [mg63273] Returning an empty sequence
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Fri, 23 Dec 2005 05:08:28 -0500 (EST)
  • References: <200512220504.AAA05673@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Dec 22, 2005, at 12:04 AM, 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)?

Sequence[] always gets evaluated unless the function has the  
attribute SequenceHold or HoldAllComplete which Switch does not.  You  
can unprotect Switch to set the SequenceHold attribute but I must ask  
why you would want to do this?  You can get the same effect by having  
f take the values "foo",{},{"bar"} and writing Sequence[f[n]]  
wherever it's appropriate.

Regards,

Ssezi


  • Prev by Date: Re: Converting Strings to Ints.
  • Next by Date: Moving an outsider to the closest point on the boundary
  • Previous by thread: Re: Returning an empty sequence
  • Next by thread: Re: Returning an empty sequence