What is ___ vs _ in Mathematica ?

  • Context: Mathematica 
  • Thread starter Thread starter Physics_rocks
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around the use of pattern matching in Mathematica, specifically focusing on the meanings of different pattern symbols such as "_", "__", and "___" in function declarations. Participants explore the implications of these symbols in the context of defining functions and their parameters.

Discussion Character

  • Technical explanation

Main Points Raised

  • One participant asks about the meaning of "lis_list" in the context of a function declaration, expressing uncertainty about the use of "___".
  • Another participant suggests that "___" does not have any effect, implying it may not be necessary.
  • A different participant clarifies that "_" represents a single expression, while "___" represents a sequence of 0 or more expressions, and mentions "__" for a sequence of 1 or more expressions.
  • One participant interprets "lis_list" to mean that "lis" is restricted to matching a list, recommending that others refer to Mathematica's help system for more information on pattern matching.

Areas of Agreement / Disagreement

Participants express differing views on the necessity and effect of "___", with some providing explanations while others question its relevance. The discussion does not reach a consensus on the implications of these patterns.

Contextual Notes

Participants reference the Mathematica help system for further clarification on pattern matching, indicating that there may be additional nuances not fully explored in the discussion.

Physics_rocks
Messages
12
Reaction score
0
Hi guys ,

I have the next declaration in Mathematica :

myfunc [lis_list]

and myfync [x_,y___]

what does "lis_list" means ? I know that when I want to declare a variable of a function
I must write myfunc[SomeVar_] with one _
but what are 3 times _ (meaning ___)

I hope I'm no asking a stupid question :)

thanks !
 
Physics news on Phys.org
I don't think it does anything? Testing it, it seems to have no effect.
 
_ is a pattern which can stand for any single expression, whereas ___ is a pattern that can stand for any sequence of 0 or more expressions. There is also __ which is a pattern that can stand for any sequence of 1 or more expressions.
 
Physics_rocks said:
what does "lis_list" means ?
It means that "lis" is only allowed to match a list, methinks. Mathematica's help system has a section on pattern matching -- it might be useful to go read it.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 0 ·
Replies
0
Views
2K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 18 ·
Replies
18
Views
5K