# Search Results

Results tagged with Search options answers only user 45431
9 results

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.

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
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
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
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
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
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