What does _. mean in patterns? [closed]
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
Here is a quick one, hopefully. I searched through different tutorials and documentation articles but haven't been able to find anything yet.
What does _.
mean? As in _,_.
as opposed to _,_
or _,_,_.
as opposed to _,_,_
?
Thanks!
pattern-matching argument-patterns
closed as off-topic by xzczd, Henrik Schumacher, Daniel Lichtblau, m_goldberg, Kuba⦠Sep 14 at 6:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." â xzczd, Henrik Schumacher, Daniel Lichtblau, m_goldberg, Kuba
add a comment |Â
up vote
6
down vote
favorite
Here is a quick one, hopefully. I searched through different tutorials and documentation articles but haven't been able to find anything yet.
What does _.
mean? As in _,_.
as opposed to _,_
or _,_,_.
as opposed to _,_,_
?
Thanks!
pattern-matching argument-patterns
closed as off-topic by xzczd, Henrik Schumacher, Daniel Lichtblau, m_goldberg, Kuba⦠Sep 14 at 6:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." â xzczd, Henrik Schumacher, Daniel Lichtblau, m_goldberg, Kuba
3
"I searched through different tutorials and documentation articles but haven't been able to find anything yet." Then you haven't yet learned the correct usage of document: i.stack.imgur.com/RVvvv.gif
â xzczd
Sep 13 at 17:28
@xzczd Thanks! I didn't actually know about that!
â Jmeeks29ig
Sep 13 at 17:30
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
Here is a quick one, hopefully. I searched through different tutorials and documentation articles but haven't been able to find anything yet.
What does _.
mean? As in _,_.
as opposed to _,_
or _,_,_.
as opposed to _,_,_
?
Thanks!
pattern-matching argument-patterns
Here is a quick one, hopefully. I searched through different tutorials and documentation articles but haven't been able to find anything yet.
What does _.
mean? As in _,_.
as opposed to _,_
or _,_,_.
as opposed to _,_,_
?
Thanks!
pattern-matching argument-patterns
pattern-matching argument-patterns
asked Sep 13 at 16:56
Jmeeks29ig
56929
56929
closed as off-topic by xzczd, Henrik Schumacher, Daniel Lichtblau, m_goldberg, Kuba⦠Sep 14 at 6:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." â xzczd, Henrik Schumacher, Daniel Lichtblau, m_goldberg, Kuba
closed as off-topic by xzczd, Henrik Schumacher, Daniel Lichtblau, m_goldberg, Kuba⦠Sep 14 at 6:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." â xzczd, Henrik Schumacher, Daniel Lichtblau, m_goldberg, Kuba
3
"I searched through different tutorials and documentation articles but haven't been able to find anything yet." Then you haven't yet learned the correct usage of document: i.stack.imgur.com/RVvvv.gif
â xzczd
Sep 13 at 17:28
@xzczd Thanks! I didn't actually know about that!
â Jmeeks29ig
Sep 13 at 17:30
add a comment |Â
3
"I searched through different tutorials and documentation articles but haven't been able to find anything yet." Then you haven't yet learned the correct usage of document: i.stack.imgur.com/RVvvv.gif
â xzczd
Sep 13 at 17:28
@xzczd Thanks! I didn't actually know about that!
â Jmeeks29ig
Sep 13 at 17:30
3
3
"I searched through different tutorials and documentation articles but haven't been able to find anything yet." Then you haven't yet learned the correct usage of document: i.stack.imgur.com/RVvvv.gif
â xzczd
Sep 13 at 17:28
"I searched through different tutorials and documentation articles but haven't been able to find anything yet." Then you haven't yet learned the correct usage of document: i.stack.imgur.com/RVvvv.gif
â xzczd
Sep 13 at 17:28
@xzczd Thanks! I didn't actually know about that!
â Jmeeks29ig
Sep 13 at 17:30
@xzczd Thanks! I didn't actually know about that!
â Jmeeks29ig
Sep 13 at 17:30
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
10
down vote
accepted
FullForm
will show you how an expression is really interpreted,
In[5]:= FullForm[_.]
Out[5]= Optional[Blank]
This tells you you need to look at Optional
and Blank
to understand this particular syntax.
This is especially important for infix operators like this, because for some the F1 documentation search doesn't bring up a relevant page. Take the expression
x // f
or
f @ x
Running FullForm
on either of these returns f[x]
- telling you immediately what the notation means. This is good because if you highlight the @
or //
and hit F1 you will find Prefix
and Postfix
, which aren't very helpful for understanding what those symbols mean. But FullForm
will tell you how your syntax is interpreted by the front end, and what it is sent to the kernel as.
Thanks! I'm still learning some of the basics, I should have thought to use FullForm :)
â Jmeeks29ig
Sep 13 at 17:36
1
@Jmeeks29ig - glad to help!
â Jason B.
Sep 14 at 1:45
I messed up when first commenting on this, so I cannot claim that the answer is trivial (and I wish the question hadn't been closed). It would be useful to include a few examples about howOptional
is used. So far we learnt that_.
is one shorthand forOptional
. The more common shorthand is:
, e.g.x_ : defaultValue
. With this pattern, the namex
will be assigned the explicitly writtendefaultValue
. Withf[x_.]
, the value ofx
will be taken fromDefault[f]
. Here it is necessary to have the enclosing symbolf
.
â Szabolcs
Sep 14 at 11:59
add a comment |Â
up vote
2
down vote
I'm not sure if this fully answers the question I posted, but after some more searching, I have discovered that it seems like _.
evaluates to Optional
, at least when using ReplaceAll
. An example will be better than words:
_, _. /. _Blank -> g
evaluates to:
g, Optional[g]
I know this is not a full answer, but hopefully it is at least partially helpful.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
10
down vote
accepted
FullForm
will show you how an expression is really interpreted,
In[5]:= FullForm[_.]
Out[5]= Optional[Blank]
This tells you you need to look at Optional
and Blank
to understand this particular syntax.
This is especially important for infix operators like this, because for some the F1 documentation search doesn't bring up a relevant page. Take the expression
x // f
or
f @ x
Running FullForm
on either of these returns f[x]
- telling you immediately what the notation means. This is good because if you highlight the @
or //
and hit F1 you will find Prefix
and Postfix
, which aren't very helpful for understanding what those symbols mean. But FullForm
will tell you how your syntax is interpreted by the front end, and what it is sent to the kernel as.
Thanks! I'm still learning some of the basics, I should have thought to use FullForm :)
â Jmeeks29ig
Sep 13 at 17:36
1
@Jmeeks29ig - glad to help!
â Jason B.
Sep 14 at 1:45
I messed up when first commenting on this, so I cannot claim that the answer is trivial (and I wish the question hadn't been closed). It would be useful to include a few examples about howOptional
is used. So far we learnt that_.
is one shorthand forOptional
. The more common shorthand is:
, e.g.x_ : defaultValue
. With this pattern, the namex
will be assigned the explicitly writtendefaultValue
. Withf[x_.]
, the value ofx
will be taken fromDefault[f]
. Here it is necessary to have the enclosing symbolf
.
â Szabolcs
Sep 14 at 11:59
add a comment |Â
up vote
10
down vote
accepted
FullForm
will show you how an expression is really interpreted,
In[5]:= FullForm[_.]
Out[5]= Optional[Blank]
This tells you you need to look at Optional
and Blank
to understand this particular syntax.
This is especially important for infix operators like this, because for some the F1 documentation search doesn't bring up a relevant page. Take the expression
x // f
or
f @ x
Running FullForm
on either of these returns f[x]
- telling you immediately what the notation means. This is good because if you highlight the @
or //
and hit F1 you will find Prefix
and Postfix
, which aren't very helpful for understanding what those symbols mean. But FullForm
will tell you how your syntax is interpreted by the front end, and what it is sent to the kernel as.
Thanks! I'm still learning some of the basics, I should have thought to use FullForm :)
â Jmeeks29ig
Sep 13 at 17:36
1
@Jmeeks29ig - glad to help!
â Jason B.
Sep 14 at 1:45
I messed up when first commenting on this, so I cannot claim that the answer is trivial (and I wish the question hadn't been closed). It would be useful to include a few examples about howOptional
is used. So far we learnt that_.
is one shorthand forOptional
. The more common shorthand is:
, e.g.x_ : defaultValue
. With this pattern, the namex
will be assigned the explicitly writtendefaultValue
. Withf[x_.]
, the value ofx
will be taken fromDefault[f]
. Here it is necessary to have the enclosing symbolf
.
â Szabolcs
Sep 14 at 11:59
add a comment |Â
up vote
10
down vote
accepted
up vote
10
down vote
accepted
FullForm
will show you how an expression is really interpreted,
In[5]:= FullForm[_.]
Out[5]= Optional[Blank]
This tells you you need to look at Optional
and Blank
to understand this particular syntax.
This is especially important for infix operators like this, because for some the F1 documentation search doesn't bring up a relevant page. Take the expression
x // f
or
f @ x
Running FullForm
on either of these returns f[x]
- telling you immediately what the notation means. This is good because if you highlight the @
or //
and hit F1 you will find Prefix
and Postfix
, which aren't very helpful for understanding what those symbols mean. But FullForm
will tell you how your syntax is interpreted by the front end, and what it is sent to the kernel as.
FullForm
will show you how an expression is really interpreted,
In[5]:= FullForm[_.]
Out[5]= Optional[Blank]
This tells you you need to look at Optional
and Blank
to understand this particular syntax.
This is especially important for infix operators like this, because for some the F1 documentation search doesn't bring up a relevant page. Take the expression
x // f
or
f @ x
Running FullForm
on either of these returns f[x]
- telling you immediately what the notation means. This is good because if you highlight the @
or //
and hit F1 you will find Prefix
and Postfix
, which aren't very helpful for understanding what those symbols mean. But FullForm
will tell you how your syntax is interpreted by the front end, and what it is sent to the kernel as.
edited Sep 14 at 1:43
answered Sep 13 at 17:34
Jason B.
46.2k383178
46.2k383178
Thanks! I'm still learning some of the basics, I should have thought to use FullForm :)
â Jmeeks29ig
Sep 13 at 17:36
1
@Jmeeks29ig - glad to help!
â Jason B.
Sep 14 at 1:45
I messed up when first commenting on this, so I cannot claim that the answer is trivial (and I wish the question hadn't been closed). It would be useful to include a few examples about howOptional
is used. So far we learnt that_.
is one shorthand forOptional
. The more common shorthand is:
, e.g.x_ : defaultValue
. With this pattern, the namex
will be assigned the explicitly writtendefaultValue
. Withf[x_.]
, the value ofx
will be taken fromDefault[f]
. Here it is necessary to have the enclosing symbolf
.
â Szabolcs
Sep 14 at 11:59
add a comment |Â
Thanks! I'm still learning some of the basics, I should have thought to use FullForm :)
â Jmeeks29ig
Sep 13 at 17:36
1
@Jmeeks29ig - glad to help!
â Jason B.
Sep 14 at 1:45
I messed up when first commenting on this, so I cannot claim that the answer is trivial (and I wish the question hadn't been closed). It would be useful to include a few examples about howOptional
is used. So far we learnt that_.
is one shorthand forOptional
. The more common shorthand is:
, e.g.x_ : defaultValue
. With this pattern, the namex
will be assigned the explicitly writtendefaultValue
. Withf[x_.]
, the value ofx
will be taken fromDefault[f]
. Here it is necessary to have the enclosing symbolf
.
â Szabolcs
Sep 14 at 11:59
Thanks! I'm still learning some of the basics, I should have thought to use FullForm :)
â Jmeeks29ig
Sep 13 at 17:36
Thanks! I'm still learning some of the basics, I should have thought to use FullForm :)
â Jmeeks29ig
Sep 13 at 17:36
1
1
@Jmeeks29ig - glad to help!
â Jason B.
Sep 14 at 1:45
@Jmeeks29ig - glad to help!
â Jason B.
Sep 14 at 1:45
I messed up when first commenting on this, so I cannot claim that the answer is trivial (and I wish the question hadn't been closed). It would be useful to include a few examples about how
Optional
is used. So far we learnt that _.
is one shorthand for Optional
. The more common shorthand is :
, e.g. x_ : defaultValue
. With this pattern, the name x
will be assigned the explicitly written defaultValue
. With f[x_.]
, the value of x
will be taken from Default[f]
. Here it is necessary to have the enclosing symbol f
.â Szabolcs
Sep 14 at 11:59
I messed up when first commenting on this, so I cannot claim that the answer is trivial (and I wish the question hadn't been closed). It would be useful to include a few examples about how
Optional
is used. So far we learnt that _.
is one shorthand for Optional
. The more common shorthand is :
, e.g. x_ : defaultValue
. With this pattern, the name x
will be assigned the explicitly written defaultValue
. With f[x_.]
, the value of x
will be taken from Default[f]
. Here it is necessary to have the enclosing symbol f
.â Szabolcs
Sep 14 at 11:59
add a comment |Â
up vote
2
down vote
I'm not sure if this fully answers the question I posted, but after some more searching, I have discovered that it seems like _.
evaluates to Optional
, at least when using ReplaceAll
. An example will be better than words:
_, _. /. _Blank -> g
evaluates to:
g, Optional[g]
I know this is not a full answer, but hopefully it is at least partially helpful.
add a comment |Â
up vote
2
down vote
I'm not sure if this fully answers the question I posted, but after some more searching, I have discovered that it seems like _.
evaluates to Optional
, at least when using ReplaceAll
. An example will be better than words:
_, _. /. _Blank -> g
evaluates to:
g, Optional[g]
I know this is not a full answer, but hopefully it is at least partially helpful.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I'm not sure if this fully answers the question I posted, but after some more searching, I have discovered that it seems like _.
evaluates to Optional
, at least when using ReplaceAll
. An example will be better than words:
_, _. /. _Blank -> g
evaluates to:
g, Optional[g]
I know this is not a full answer, but hopefully it is at least partially helpful.
I'm not sure if this fully answers the question I posted, but after some more searching, I have discovered that it seems like _.
evaluates to Optional
, at least when using ReplaceAll
. An example will be better than words:
_, _. /. _Blank -> g
evaluates to:
g, Optional[g]
I know this is not a full answer, but hopefully it is at least partially helpful.
answered Sep 13 at 17:29
Jmeeks29ig
56929
56929
add a comment |Â
add a comment |Â
3
"I searched through different tutorials and documentation articles but haven't been able to find anything yet." Then you haven't yet learned the correct usage of document: i.stack.imgur.com/RVvvv.gif
â xzczd
Sep 13 at 17:28
@xzczd Thanks! I didn't actually know about that!
â Jmeeks29ig
Sep 13 at 17:30