Skip to main content
added 1258 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

If I am understanding you:

x : {{__} ..}

See Repeated for more information and additional options. Also see RepeatedNull while you're there.

Make sure you understand BlankSequence and Pattern as well.


Here is a breakdown of the expression above. First let us view the FullForm which is as close to the way Mathematica sees it as possible:

FullForm[ x:{{__}..} ]
Pattern[x,
  List[
    Repeated[
      List[
        BlankSequence[]
      ]
    ]
  ]
]

This expanded form is useful to remove any ambiguity in Mathematica's parsing.

Therefore from the inside out we have (short form : long form : description):

__ : BlankSequence[] : one or more arguments with any head

{ } : List[ ] : inside the head List

.. : Repeated[ ] : one or more arguments matching the given pattern

{ } : List[ ] : inside the head List

x: : Pattern[x, ] : a unique expression that matches the given pattern, named x

Pay attention to this last point: naming the pattern changes the way it behaves, such that it represents a unique expression. Consider this superficially similar pattern:

x : {{a__} ..}

This will only match e.g. {{1, 2}, {1, 2}, {1, 2}} but not {{1, 2}, {3}, {4, 5, 6}} because by naming the first sequence 1, 2 all other sequences must be identical. Simply matching the pattern a__ independently is not enough.

If I am understanding you:

x:{{__}..}

See Repeated for more information and additional options. Also see RepeatedNull while you're there.

Make sure you understand BlankSequence and Pattern as well.

If I am understanding you:

x : {{__} ..}

See Repeated for more information and additional options. Also see RepeatedNull while you're there.

Make sure you understand BlankSequence and Pattern as well.


Here is a breakdown of the expression above. First let us view the FullForm which is as close to the way Mathematica sees it as possible:

FullForm[ x:{{__}..} ]
Pattern[x,
  List[
    Repeated[
      List[
        BlankSequence[]
      ]
    ]
  ]
]

This expanded form is useful to remove any ambiguity in Mathematica's parsing.

Therefore from the inside out we have (short form : long form : description):

__ : BlankSequence[] : one or more arguments with any head

{ } : List[ ] : inside the head List

.. : Repeated[ ] : one or more arguments matching the given pattern

{ } : List[ ] : inside the head List

x: : Pattern[x, ] : a unique expression that matches the given pattern, named x

Pay attention to this last point: naming the pattern changes the way it behaves, such that it represents a unique expression. Consider this superficially similar pattern:

x : {{a__} ..}

This will only match e.g. {{1, 2}, {1, 2}, {1, 2}} but not {{1, 2}, {3}, {4, 5, 6}} because by naming the first sequence 1, 2 all other sequences must be identical. Simply matching the pattern a__ independently is not enough.

added 209 characters in body
Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

If I am understanding you:

x:{{__}..}

See Repeated for more information and additional options. Also see RepeatedNull while you're there.

Make sure you understand BlankSequence and Pattern as well.

If I am understanding you:

x:{{__}..}

If I am understanding you:

x:{{__}..}

See Repeated for more information and additional options. Also see RepeatedNull while you're there.

Make sure you understand BlankSequence and Pattern as well.

Source Link
Mr.Wizard
  • 273.1k
  • 34
  • 595
  • 1.4k

If I am understanding you:

x:{{__}..}