Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: Function argument types

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112952] Re: Function argument types
  • From: Albert Retey <awnl at gmx-topmail.de>
  • Date: Thu, 7 Oct 2010 03:37:47 -0400 (EDT)
  • References: <i8h7o3$ci1$1@smc.vnet.net>

Am 06.10.2010 09:16, schrieb Sam Takoy:
> Hi,
> 
> I can't see to find the answer to this basic question:
> 
> What's the difference between
> 
> f[n_?Integer]:=

this pattern matches if Integer[n] evaluates to True (not something very
likely to happen and most probably not what you wanted...). A more
useful construct would be

f[n_?IntegerQ] := ...


> and
> 
> f[n_Integer]:=

This matches, if n has Head Integer, which is true for all integer
values. In this case n_Integer and n_?IntegerQ are almost the same, but
there could be some special cases where one could match and the other
not, but these are not what you usually expect anyway, e.g.

MatchQ[Integer[a], n_Integer]
-> True
MatchQ[Integer[a], n_?Integer]
-> False


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

Pattern matching in general, PatternTest in particular...

hth,

albert


  • Prev by Date: Re: Function argument types
  • Next by Date: evaluation of a function via mathematica from clojure using the
  • Previous by thread: Re: Function argument types
  • Next by thread: Re: Function argument types