18
votes
Accepted
How can I view the minimal required arguments of a Wolfram Language function?
You can use SyntaxInformation:
SyntaxInformation /@ {Sin, Replace} // Column
17
votes
Accepted
Define function that behaves almost identically to Mathematica function
If you want to constrain it to only options from ListPlot, you could use OptionsPattern in combination with ...
16
votes
How to define a function reminding of names of the independent variables?
You can get the behavior you ask for if you define your function to work with an association. The key-value paradigm provides syntax close but not exactly as you describe.
Simple approach
...
14
votes
Accepted
How to pass arguments to the list of functions?
f[x_, y_] = x + y;
g[x_, y_] = x^3 + y^2 + 2 x;
functions = {f, g};
Using Map
...
14
votes
Accepted
Map a two argument function to every element on list
Since you're looking to learn more about functional style, I'll elaborate rather than just provide an answer.
We start with our table:
...
12
votes
Accepted
How to supply argument to pure function when slot is already defined?
If you don't want to follow some suggestions made in comments and use the Function with named arguments (and there may be valid reasons to be willing to avoid that),...
11
votes
How to define a function reminding of names of the independent variables?
If this is just to help entering values in the correct order (and not to be permanently visible), you can possibly use a Placeholder. Reevaluating ...
9
votes
Define function that behaves almost identically to Mathematica function
The usual way to define a Wolfram Language function that takes n arguments and an arbitrary number of options is like this:
...
9
votes
Accepted
Make a function work by the keyword instead of argument position while evaluating
It is possible to do with Options:
...
7
votes
Accepted
Testing if list elements are numerical
TestFun[listArg_?(VectorQ[#, NumericQ] &)] := Sum[listArg[[k]], {k, 1, m}]
TestFun2[{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}]
55
or
...
6
votes
Mapping between lists and Mapping Formats
Partition[connectionsOrder, 2, 1, {1, -1}, {}, Rule]
...
6
votes
Accepted
What Does this Syntax Mean in Ouput from DSolve?
$c_1$ is a function that takes $x$ and $\frac{1}{2}(y^2+z^2)$ as its arguments. I do not know why it shows it this way. In Maple, same solution is shown as $f \left(x , y , z\right) = F1 \left(x , y^{...
6
votes
Accepted
Define a function with sparsearray
I corrected some of the syntax issues in your code. While this can likely be improved, I think it is beneficial to see what precisely can be changed to make your code able to run. Please find it below,...
6
votes
Collect the coefficients through the Cos argument
One way, assuming expr is a linear combination of cosines:
...
5
votes
How do I pass a "list of lists" as the argument to a function of the form F[x,y]?
Apply at Level 1:
F @@@ list
{F[a1, b1], F[a2, b2], F[a3, b3], F[an, bn]}
5
votes
How to make functional rules not depend on an argument?
It's just like defining a function. Make x the name of a pattern, not a literal symbol:
...
5
votes
Keep irrelevant variables outside function arguments
Clear["Global`*"]
f1[x_, y_ : y] := x^2 + y
f2[x_, y_ : y] := (1 + x) f1[x, y]
f3[x_, y_ : y] := Derivative[1, 0][f1][x, y] + f2[x + 1, y]
In each case, ...
5
votes
Accepted
Mapping between lists and Mapping Formats
BlockMap can do more of the work than you are allowing it to:
BlockMap[Apply[Rule], connectionsOrder, 2, 1]
...
5
votes
Accepted
What is the usefulness of adding a colon ":" to arguments in the declaration of a function?
It is useful when your pattern does not start with _. Suppose your pattern is a list of integers,
...
5
votes
4
votes
Accepted
How can I fix my Simpson's rule integration code?
I can recommend more practical for numerical calculations next definition:
...
4
votes
Accepted
Defining function with arguments in a specific pattern similar to Graphics[]
ClearAll[f1, f2]
f1[gr_, clr_] := Graphics@Style[gr, clr]
f2[args : __, opts : OptionsPattern[Show]] := Show[f1 @@@ Partition[{args}, 2], opts]
Example:
...
4
votes
Make a function work by the keyword instead of argument position while evaluating
You could use associations as follows:
f[in_:<||>]:=With[{m=Merge[{in,<|a->1,b->2,c->3|>},First]},
m[a]+m[b]+m[c]
];
Examples:
...
4
votes
Accepted
3
votes
Accepted
How to represent functions values Table in a form of columns with arguments and values?
You can use TableForm:
...
3
votes
Pass arguments to a function within a function within a function
Perhaps you can use ParametricNDSolveValue instead. For your example:
...
3
votes
How can I fix my Simpson's rule integration code?
The function MyPlot, which is the model for your implementation, is specialized to a certain argument pattern and won't evaluate when given ...
3
votes
Accepted
How to extract arguments of color spaces and determine brightness of said colors?
RGBColor and GrayLevel are just semantic wrappers.
FullForm[Orange]
RGBColor[1,0.5,0]
...
3
votes
How to extract arguments of color spaces and determine brightness of said colors?
You might try working in the hue, saturation, and brightness color space for this.
Suppose I have a RGB color with red value 0.1, green value 0.8 and blue value 0.7
...
3
votes
Accepted
How to modify the argument of a specific function below?
I don't think it's a good idea to set variables in the way you're doing it. Passing variables "by reference" is an idea that comes from other programming languages (C and C++, for example).
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
arguments × 60functions × 22
function-construction × 17
list-manipulation × 9
argument-patterns × 5
replacement × 4
scoping × 4
plotting × 3
matrix × 3
vector × 3
functional-style × 3
style × 3
hold × 3
rule × 3
optional-arguments × 3
performance-tuning × 2
mathematical-optimization × 2
pattern-matching × 2
notebooks × 2
color × 2
syntax × 2
map × 2
scripting × 2
variable × 2
pure-function × 2