MathGroup Archive 2010

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

Search the Archive

Re: Pattern: x_List with conditions on elements

  • To: mathgroup at
  • Subject: [mg110924] Re: Pattern: x_List with conditions on elements
  • From: "Nasser M. Abbasi" <nma at>
  • Date: Mon, 12 Jul 2010 01:03:37 -0400 (EDT)
  • References: <i13tqo$7h7$> <i15qqr$ktt$> <i1c5s1$ccu$>
  • Reply-to: nma at

On 7/11/2010 3:19 AM, telefunkenvf14 wrote:

> How much does Mathematica really benefit by narrowing types of inputs?
> (besides the benefit of overloading symbols) For example, does it help
> above and beyond simply declaring, say,
> SetAttributes[MyFunction]={NumericFunction}?
> -RG

It is not Mathematica which benefits, it is your program which will.

If you know that a function you are writing will only accept input which 
must be numeric, then better to define the function as such.

This will make your program more reliable, because if somewhere else you 
made a mistake calling the function with the wrong argument, i.e. 
something other than a numeric argument, then you'll catch that right 
away, at the call time, not some time later down the road.

If in addition, you know something about the range of values the input 
must be within, it is better to also add this as well.  Something like


much better than just writing


Since Mathematica does not have data types, the above seems to me to be 
one way around this that I learned.

In languages with type definition, one can define a type to be numeric 
and positive, and then declare variables of that type, then the compiler 
will check that caller argument matches the type of called parameter. 
Learning how to use correct type definition to match the problem at 
hand, can lead to programs with much less errors.


  • Prev by Date: strange bahavior of ArcSinh
  • Next by Date: Re: multivariate interpolation
  • Previous by thread: Re: Pattern: x_List with conditions on elements
  • Next by thread: Re: Pattern: x_List with conditions on elements