PRODUCTS
Mathematica
Mathematica for Students
Mathematica for the Classroom
Mathematica Personal Grid Edition
grid
Mathematica
web
Mathematica
Mathematica Player
(free download)
Mathematica Player Pro
Wolfram
Workbench
Mathematica
Applications
PURCHASE
Online Store
Other Ways to Buy
Volume & Site Licensing
Contact Sales
Software
Service
Upgrades
Training
Books
FOR USERS
All User Resources
Product Registration
Technical Support
Customer Service
Developer Support
Does My Site Have a License?
Free Seminars
Certified Training
Documentation & Examples
Tutorial Screencasts
Video Gallery
Demonstrations Project
Education Portal
Student Resources
COMPANY
About Wolfram Research
News & Events
Wolfram Blog
Employment Opportunities
History of
Mathematica
Stephen Wolfram's Home Page
Contact Us
OUR SITES
Demonstrations Project
MathWorld
Integrator
Wolfram Functions Site
Wolfram Blog
Mathematica Journal
Wolfram Library Archive
Wolfram
Tones
Wolfram Science
Stephen Wolfram
DOCUMENTATION CENTER SEARCH
Mathematica
>
Mathematica
Tutorial
PatternSequence
Functions »
|
Patterns
Tutorials »
Pattern Sequences
In some cases you may need to specify pattern sequences that are more intricate than things like
x__
or
x
..
; for such situations you can use
PatternSequence
[
p
1
,
p
2
,
...
]
.
PatternSequence
[
p
1
,
p
2
,
...
]
a sequence of arguments matching
p
1
,
p
2
,
...
Pattern sequences.
This defines a function with two or more arguments, grouping the first two.
In[1]:=
Evaluate the function for different numbers of arguments.
In[2]:=
Out[2]=
This picks out the longest run of the sequence
a
,
b
in the list.
In[3]:=
Out[3]=
The empty sequence,
PatternSequence
[]
, is sometimes useful to specify an optional argument.
This picks out expressions with exactly one or two arguments.
In[4]:=
Out[4]=
RELATED TUTORIALS
Patterns
© 2008 Wolfram Research, Inc.