|
|
|
|
|
by jazzyjackson
2047 days ago
|
|
It's not really an operator, it's part of a pattern-matching syntax. "_" is called Blank and matches anything. Putting a name in front of it just makes it available by name -- like referring to capture groups in a regex. So when you call a function on some argument or list of arguments, the interpreter looks up all the function definitions and finds one with a pattern that matches. Double[x_] := 2 * x
Will work for Double[3] but not for Double[3, 2], the latter doesn't match any patterns, and the interpreter doesn't know what to do with it. You would have to define another function with the same name to handle other patterns, like overloading in C++You can further constrain the pattern to types like this: Double[x_Integer] := 2 * x
And now the pattern only matches integers.
More in the manual, "Patterns"[0] and "More about Patterns"[1][0] https://www.wolfram.com/language/elementary-introduction/2nd... [1] https://www.wolfram.com/language/elementary-introduction/2nd... |
|