Questions tagged [argument-patterns]
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.
171
questions
1
vote
2
answers
85
views
How to pass arguments of outer function into inner function implicitly?
Consider the following setup:
...
0
votes
1
answer
128
views
How can I effectively input more than two list arguments into a function?
I am trying to input more than two list arguments into a function. For example, I have written the following code:
...
1
vote
2
answers
51
views
In a function definition, how should I declare an XMLObject["Document"] argument?
Here we have an XMLObject["Document"]:
...
5
votes
3
answers
129
views
Implementing symmetry assumptions in FullSimplify
I want to symmetrise a long expression, M, that involves a function of 4 arguments, f[u1,u2,d1,d2], and its products (for ...
2
votes
1
answer
100
views
Passing argument to a function
I want to apply a function to a list. The Code for that is:
Function[x,x^2]/@list
>1,4,9
But when I want to made a function of that function, passing the ...
5
votes
1
answer
73
views
Assumptions about indexed variables
I am interested in the most efficient way to impose assumptions on indexed variables. In the following stylized problem, the following code
...
0
votes
2
answers
58
views
Pattern for Matching for Numeric 3 Vector [closed]
I'm trying to write a basic molecular dynamics sim in Mathematica and would like to define a function calculateForces that takes two arguments. The first is a 3 vector for the coordinates of a ...
2
votes
2
answers
103
views
Is it possible to combine a default value in a function definition with type-checking, in case the optional parameter is actually given in a call?
1.) In a function definition, e.g.
...
1
vote
3
answers
72
views
How can I write a function definition which gets another function as parameter whether the parameters of the function match a pattern?
One can write functions which depend on the type of actual parameter before they are actually called. E.g.:
...
0
votes
1
answer
59
views
How can I distinguish between different structures of actual function parameters?
Overloading functions for different types of parameters is very powerful.
I can easily write different versions of a function depending on the function parameters being Integer, Real, Complex, Sring ...
9
votes
1
answer
458
views
How do I correctly apply patterns to function arguments using Pattern (:), PatternTest (?), and Condition (/;)
Given:
Clear[func];
listOfLists = {{a, b}, {c, d, e}};
listOfRules = {a -> b, c -> d};
I can discern between listOfLists and listOfRules using MatchQ:
...
6
votes
1
answer
305
views
A problem on the pattern (:) of Heads
I defined
Clear[f, g]
f[(h : Exp | Log)[x_]] := x;
g[(h : Log | Exp)[x_]] := x;
The code gives a weird result:
...
2
votes
2
answers
157
views
'Update' and how to use variables to define patterns in functions' arguments...?
This seems like an obvious issue that I have nevertheless never encountered before.
In a package, I want to use a variable to define a pattern that is used in the definition of some functions. However ...
5
votes
3
answers
236
views
Part specification using list elements
How to use a list to specify part of another nested list mat? We don't want to write ...
4
votes
1
answer
81
views
How to specify the type/Head of the optional named arguments to a function?
I am trying to improve my own dsolver API. Currently it takes optional arguments.
Is it possible to specify that an optional argument should say be String only? Or List Only? Or Integer only? and so ...