MathGroup Archive 2009

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

Search the Archive

Function returns null

  • To: mathgroup at smc.vnet.net
  • Subject: [mg104689] Function returns null
  • From: Michael Greene <mgreene at csumb.edu>
  • Date: Sat, 7 Nov 2009 06:46:14 -0500 (EST)

I'm getting an unexpected result when I remove a print statement from my
function. The function computes a single digit sum of digits and returns
what I expect as long as the print statement just prior to the function exit
is present. I can verify that by invoking the function within a print
statement, e.g.,

Print["sOd returned - ",sOd[3329]]

When I remove the print  within the function, the function returns a null
result. What simple point am I missing ? Does the := operator have something
to do with this?

Here is the function: (with embedded print statement)

sOd[x0_] := Module[{sodv, x, digit},
  x = IntegerPart[x0]; (* ensure we have an integer input*)
  sodv = x;
  If[(x > 9), {              (* sum digits if input has two or more digits*)
     sodv = 0;
     While[x > 0,
      digit = (FractionalPart[x /10])*10;
      sodv = sodv + digit;
      x = IntegerPart[x/10];
      ];
     sodv = sOd[sodv];  (* check for multiple digit sum  *)
     }
    ]
   Print["sOd returns -", sodv];  (* remove this and function returns null*)
  Return[sodv];             (* return single digit sum *)
  ]


Thanks,
Michael Greene



  • Prev by Date: Re: SphericalPlot3D ColorFunction problem
  • Next by Date: Re: Mathematica skill level snippet(s)
  • Previous by thread: Re: Strange behavior when using pattern match and HoldAll
  • Next by thread: Re: Function returns null