Re: Which is better, foo[n_Integer] or foo[n_?IntegerQ] ?
- To: mathgroup at smc.vnet.net
- Subject: [mg103804] Re: [mg103770] Which is better, foo[n_Integer] or foo[n_?IntegerQ] ?
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Wed, 7 Oct 2009 07:01:18 -0400 (EDT)
- References: <200910051716.NAA10520@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
I think the first will be faster, but you'd have to test it in your application to be sure. Bobby On Mon, 05 Oct 2009 12:16:12 -0500, Nasser Abbasi <nma at 12000.org> wrote: > I am trying to improve some code I wrote by making the function > definition > more clear by setting restriction on the parameters. > > I noticed that I could write the following > > foo[n_Integer] := n^2 > boo[n_?IntegerQ] := n^2 > > Both the above mean the same thing to me. i.e. the function is defined to > take only integer argument. > > Is one better to use? or any one is just as good? (the first uses 2 less > characters!) > > thank you, > --Nasser > > > > > -- DrMajorBob at yahoo.com
- References:
- Which is better, foo[n_Integer] or foo[n_?IntegerQ] ?
- From: "Nasser Abbasi" <nma@12000.org>
- Which is better, foo[n_Integer] or foo[n_?IntegerQ] ?