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.

25 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
8 votes
0 answers
74 views

Why does Longest not work on OptionsPattern?

When having a function with optional arguments and options, I frequently find myself writing something like this: ...
Lukas Lang's user avatar
7 votes
0 answers
165 views

Exceeding recursion limit with no obvious recursion: Optional pattern-matching causing nonlocal behavior

So, I've come across something strange, and wanted to get a deeper understanding of what was going on. Consider the following code: ...
thorimur's user avatar
  • 9,010
6 votes
0 answers
119 views

Difference between the infinite rewriting behavior of evaluation and ReplaceRepeated

In the documentation tutorial/Evaluation it's said that: Every time the expression changes, the Wolfram Language effectively starts the evaluation sequence over ...
asd1dsa's user avatar
  • 573
6 votes
0 answers
366 views

About the OptionsPattern[] approach of inheriting Options

Szabolcs showed in this post, that there are possibly two approaches to inherit function options. He recommended the Join approach. At first, I agreed. But today I ...
matheorem's user avatar
  • 17.1k
5 votes
0 answers
396 views

Syntax error for optional pattern, but only in debugger

This expression (explained here by Leonid) evaluates fine unless Evaluation->Debugger is enabled: h[x : (_Integer) : 1] := x Syntax::sntxf: "x:" cannot be ...
ssch's user avatar
  • 16.6k
4 votes
0 answers
114 views

Lint checker for overlapping or conflicting function signature patterns

In building a system like Mathics (or anything having the number of builtin functions of Mathematica) there are lots of function definitions. I would like to sanity check or lint check the pattern in ...
rocky's user avatar
  • 245
4 votes
0 answers
77 views

Preventing $-renaming of pattern names in lexically-scoped constructs

When you use a lexically-scoped construct like With or Function to perform replacements in an expression, Mathematica might ...
thorimur's user avatar
  • 9,010
4 votes
0 answers
76 views

How to get f[x] to match with f[c_., x] when OneIdentity doesn't match

After setting: SetAttributes[f, OneIdentity] Default[f] = 1; We have the following successful matches: ...
QuantumDot's user avatar
  • 19.7k
2 votes
0 answers
335 views

How to test for arguments for a pattern that is of a positive Integer OR Infinity so that both filter through to the definition on RHS?

How can I filter an argument of a function so that definition works on positive Integers (y >= 0) or Infinity? It will ...
Jules Manson's user avatar
  • 2,457
2 votes
0 answers
79 views

How to specify complicated patterns in function arguments?

Unfortunately, I have not found in documentation how to create complicated patterns in arguments of a function Consider a toy example. Say, I would like to have a simple function ...
Konstantin's user avatar
2 votes
0 answers
103 views

How does Mathematica choose which function definition to use?

I was wondering what the process of matching function arguments arguments against different function definitions actually looks like for Mathematica. (Just to be clear, I'm not simply looking for an ...
thorimur's user avatar
  • 9,010
2 votes
0 answers
95 views

Is there something like a function pattern test?

Is there something like a function pattern test? function[x_?FunctionQ]:=Module[{},] In order that Mathematica can tell if the argument is a function or a ...
Mirko Aveta's user avatar
  • 2,192
2 votes
0 answers
111 views

Automating generation of argument error messages

You can run into messages like DistributionFitTest["kk", "TestConclusion"] ...
masterxilo's user avatar
  • 5,739
1 vote
1 answer
94 views

How to define a mixed pattern consisting of string and regular patterns for function definition (using SetDelayed)?

I'm kinda stuck here, and I could really use some help: I want to define a function, let's call it quarterValue, that accepts a ...
joka's user avatar
  • 332
1 vote
0 answers
63 views

How conflicting patterns are resolved?

I often find myself doing something like this (probably poor example, sorry) f[x_] := 0 f[x_Plus] := 1 In the back of my mind generally ...
Weather Report's user avatar
1 vote
0 answers
39 views

Is there a way to get the calling information inside the body of a function defined using down value?

Suppose a function has multiple argument structure like follows: ...
user13892's user avatar
  • 9,385
1 vote
1 answer
118 views

Functions definitions with variable arguments

How do you define a variable amount of functions with a variable amount of arguments? I don't get the reference at all : ...
Rodrigo's user avatar
  • 101
1 vote
0 answers
92 views

Using Two Arguments on the Same Function

I'm having some trouble wrapping my head around how I would go about using two arguments in one function. In the first section of the code below, I have scraped some "tweets" on the Seeking Alpha ...
Vic Jongmin Youn's user avatar
1 vote
0 answers
59 views

Is there any point to using a variable as a function parameter?

Normally one only sees patterns as function parameters: fun1[x_]:=x^2 Is there any point to using a variable in a function definition: ...
Tyler Durden's user avatar
  • 4,090
0 votes
0 answers
72 views

How to specify specific (custom) function arguments

Suppose that I want to have a function that is evaluated only when a user-specific, predefined flag is given out of a list of possible flags. For example ...
hal's user avatar
  • 783
0 votes
0 answers
48 views

Detecting whether a function is initially defined with the form R[x,y] or R[x_,y_], etc

I have a very long code that may have errors in definition of functions and I want to trace these errors. Is there any attribute or function to detect whether a function is initially defined in the ...
Alex97's user avatar
  • 410
0 votes
0 answers
288 views

How to convert Symbol to Number?

Question I have a variable x which is associated with the number 1 : x= 1 In the program, I faced with the data type problem ...
ten's user avatar
  • 113
0 votes
0 answers
56 views

Head of complex sum

We have: 1 + 2 I + 3 + 4 I // Head Complex and 1 + 2 I + 3/5 + 4/5 I // Head Complex But we get: ...
murray's user avatar
  • 11.9k
0 votes
0 answers
81 views

Delayed Rule right-hand-side mis-evaluation

Outline I am trying to create a rule that will give me a minus sign if the number of times A is applied on X is odd where A is some οperator and X a random quantity. Some of the configurations of ...
Viktor  Gakis's user avatar
0 votes
0 answers
50 views

Defining functions with pattern as argument

I want to define a function such that f[18/17 h[y][z]] = 18/17 z for any function h[y][z]. I first tried with ...
apt45's user avatar
  • 1,648