Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Favorites infavorites:mine
infavorites:1234
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with Search options answers only user 45431

Questions concerning argument patterns used as formal arguments in function definitions (e.g., := expressions) to restrict the kinds of values that can be passed as actual arguments. Also questions about how such patterns can be used to achieve function overloading.

11
votes
If you want to name your variables, but don't want to repeat the pattern test ?NumericQ for each variable, you can use PatternSequence: f[PatternSequence[a1_, a2_, a3_, a4_, a5_]?NumericQ] := {a1, a1 …
answered Oct 22 '18 by Carl Woll
3
votes
This is basically a duplicate of Define function from expression. This time I will provide a function to do the conversion. Here is the function: toFunc[expr_, h_]:=h[X_, Y_]:=Block[{x,y}, x[i_][ …
answered Oct 24 '17 by Carl Woll
10
votes
You can use PatternSequence: f[PatternSequence[x_,y_,z_]?NumericQ, PatternSequence[k_,l_]?IntegerQ] := stuff[x,y,z,k,l] Check: f[1,2,3,π,5] f[π,1,2,3,4] f[1, 2, 3, π, 5] stuff[π, 1, 2, 3 …
answered Oct 22 '18 by Carl Woll
6
votes
The pattern x__ is a Pattern object: x__ //FullForm Pattern[x,BlankSequence[]] While the pattern object represents multiple arguments in a Rule or a function definition, it is a single object. …
answered Mar 16 by Carl Woll
1
vote
Why not use an auxiliary head to handle the orderless attribute? For example: SetAttributes[s, Orderless]; expr = f2[{a,b},{c,d}] g1[x]+f2[{a,b},{d,c}] g2[x]+f2[{b,a},{c,d}] g3[x] /. List -> s; expr …
answered Dec 19 '18 by Carl Woll
9
votes
In M9 and earlier, the default value must match any pattern restrictions. In your example, the head of the default is not Integer, and so the default value could never be triggered. In either 10.2 or …
answered Aug 18 '18 by Carl Woll
3
votes
Update I was reading the comments to the question, and found that @Kuba had already provided the following answer. I think it's the cleanest solution, so it deserves to be an answer, but please credi …
answered Jun 14 '17 by Carl Woll
1
vote
You could define an UpValues for λ to encapsulate your known relation: SetAttributes[c, Constant] Dt[f == c/λ, f] 1 == -c Dt[λ, f]/λ^2 Hence, we can define: λ /: Dt[λ, f] = -λ^2/c -λ^2/c …
answered Oct 8 '18 by Carl Woll
3
votes
You can also define BadData as a pure function: BadData[bad_] := First[#] == bad& Then: DeleteCases[data, _?(BadData[1.1])] {{1, 5}, {2, 7}} Another possibility is: BadData[bad_] := EqualT …
answered May 1 by Carl Woll