MathGroup Archive 2002

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

Search the Archive

Re: Help: Why no output?

  • To: mathgroup at
  • Subject: [mg34960] Re: [mg34941] Help: Why no output?
  • From: Tomas Garza <tgarza01 at>
  • Date: Sat, 15 Jun 2002 02:27:50 -0400 (EDT)
  • References: <>
  • Sender: owner-wri-mathgroup at

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>
To: mathgroup at
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?
> Thanks for your help.
> Kezhao Zhang

  • Prev by Date: Re: Help: Why no output?
  • Next by Date: RE: Help: Why no output?
  • Previous by thread: Help: Why no output?
  • Next by thread: Re: Help: Why no output?