Linked Questions

7
votes
2answers
380 views

Is it possible to use PatternTest and Optional value on one Pattern simultaneously? [duplicate]

Possible Duplicate: How to Combine Pattern Constraints and Default Values for Function Arguments First a simple example: define a function "add" with two arguments, and its second argument should ...
3
votes
1answer
163 views

What is the syntax to combine conditions and options? [duplicate]

How can a condition and an option be written on the RHS of a function? I.e. ...
527
votes
19answers
131k views

Where can I find examples of good Mathematica programming practice?

I consider myself a pretty good Mathematica programmer, but I'm always looking out for ways to either improve my way of doing things in Mathematica, or to see if there's something nifty that I haven't ...
38
votes
4answers
3k views

Can a function be made to accept a variable amount of inputs?

I have a function that takes two inputs and processes them for a single output. What I need is one that can take a varying number of inputs. and process them to a single output. Is this possible in ...
25
votes
2answers
2k views

Using a list of tuples in a pure function

I want to use a list of tuples within a function to make assignments. Say I want to make assignments of the form value[i,j] = val What I have is a list of ...
26
votes
2answers
475 views

Version inconsistency with optional arguments: what if the default value doesn't match the pattern?

I just came across some weird behaviour. Take this function definition: ClearAll[f] f[vs_List : All] := "match" The default value of ...
9
votes
4answers
1k views

Function argument to default under certain condition

Inspired by this and this question (and how I handle this in practice), what is the best way to default a function value when a certain condition is met? For example, if a function is defined as: <...
8
votes
1answer
550 views

define a function with optional arguments

I have defined a function as follows: ...
9
votes
1answer
229 views

Why is this syntax for patterns with Optional values not supported?

I want to express Optional[PatternTest[Pattern[a,Blank[]],t],1] concisely. a : _?t : 1 is not quite this but works: ...
9
votes
1answer
199 views

Optional pattern behaves differently in version 8, 9, and 10+

We recently ran into an issue when testing Rubi on older versions. It boils down to this simple example which I didn't dare to simplify further as I cannot test it in versions < 10 ...
4
votes
1answer
702 views

Meaning of (a : _ : 1)

This is an example from Leonid Shifrin's tutorial: ...
7
votes
1answer
235 views

How can a function know in which function it was evaluated?

Hello my second question here might be very hard. I am asking for something "magical", if i define a function g and i call it inside a function f, how can g have information about the outer function ...
2
votes
1answer
121 views

Is there a shorthand for Optional with Condition?

I have a recursive function that does some work to an object for a repeatedamount of times. ...
3
votes
1answer
77 views

How to combine those rules into one? Does something like default values exist for patterns?

I am trying to set up a clever set of rules. Say, I am working symbolically with commutators comm of matrices, where for instance ...
1
vote
0answers
41 views

How to define function that variable is optional? [closed]

I want to define some function that I can do something for the troubleshooting purpose. ...