MathGroup Archive 2010

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

Search the Archive

Re: Function argument types

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112954] Re: Function argument types
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Thu, 7 Oct 2010 03:38:09 -0400 (EDT)

On 10/6/10 at 3:16 AM, sam.takoy at yahoo.com (Sam Takoy) wrote:

>I can't see to find the answer to this basic question:

>What's the difference between

>f[n_?Integer]:=

This form allows n to be anything but tests to see if n is an
integer. Execution of course happens only if the test returns true.

>and

>f[n_Integer]:=

This form specifies n is an integer. No other n will match this
pattern. So, the definition that follows will only be applied if
n is an integer.

 From a practical standpoint, there really isn't much
difference. The n_Integer form is a bit more specific and
possibly a bit faster than n_?Integer. And since this is a bit
easier to type n_Integer, this is the form I would use if I
wanted to restrict f to integer values.

>I would be happy to read more about this, but what's the keyword?

The information on patterns can be found at tutorial/PatternsOverview



  • Prev by Date: Re: For loop outputs to a list
  • Next by Date: Re: Function argument types
  • Previous by thread: Re: Function argument types
  • Next by thread: Re: Function argument types