Re: Help: Why no output?

• To: mathgroup at smc.vnet.net
• Subject: [mg34960] Re: [mg34941] Help: Why no output?
• From: Tomas Garza <tgarza01 at prodigy.net.mx>
• Date: Sat, 15 Jun 2002 02:27:50 -0400 (EDT)
• References: <200206140638.CAA04787@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```I think you'll be able to understand what's going on if you use Trace. In
the first case, since no n is given as input, the If expression reduces to
If[Length[{}]==1, Length[0.5]], and this in turn will eventually lead to a
Null statement. In the second case, the If expression remains as
If[Length[{}]==1, Times[1], Length[0.5], which eventually leads to 0, since
Length[expr] returns 0 whenever AtomQ[expr] is True (see the Help browser).

Tomas Garza
Mexico City

----- Original Message -----
From: "Kezhao Zhang" <kzhang at flashmail.com>
To: mathgroup at smc.vnet.net
Subject: [mg34960] [mg34941] Help: Why no output?

> The behavior of the following function is puzzling to me:
>
> In[1]:=f[x_, n___Integer] := If[Length[{n}] == 1, n  , Length[x]]
> In[2]:=f[0.5]  (* Nothing returned. *)
> In[3]:=f[{1,2}] (* Nothing returned. The length of x should be
> returned *)
> (* However, with the modification to f, everything works as intended
> *)
> In[4]:=f[x_, n___Integer] := If[Length[{n}] == 1, 1*n  , Length[x]]
>                                                  ^^^^^^
> In[5]:=f[0.5]
> Out[5]:=0
> In[6]:=f[{1,2}]
> Out[6]:=2
>
> Could anyone help me understand why changing n to (1*n) in the If[]
> statement makes such difference? Why doesn't f[] defined in the In[1]
> work?
>