3
$\begingroup$

I need to define a function, say f with an argument which is integer, positive and with a default value say 2. I tried:

f[n_Integer?Positive:2]:=n^4-3*n+5

or

f[n_Integer:2?Positive]:=n^4-3*n+5

but it didn't work.

$\endgroup$
1
  • $\begingroup$ Sorry, I don't see any parameter here: n is the argument of f. $\endgroup$
    – user64494
    Commented May 17 at 13:00

1 Answer 1

5
$\begingroup$

In this case, the first : which is the shorthand of Pattern cannot be omitted (yeah n_ is actually a shorthand of n : _):

f[n : _Integer?Positive : 2] := n^4 - 3 n + 5
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.