Skip to main content
fix typo
Source Link
AsukaMinato
  • 10.6k
  • 1
  • 20
  • 48

Consider the definition:

Clear[fun] fun[a_ + b_] := fun[a] + fun[b]; fun[a+b+c] (*fun[a] + fun[b] + fun[c]*) 

This works as expected. However, if we use a BlankSequence on "b":

Clear[fun] fun[a_ + b__] := fun[a] + fun[b]; fun[a + b + c] (*fun[a] + fun[b, c]*) 

it seems that BlankSequence eliminates the Plus in "b+c" and replaces it with Sequence. Has anybody a good explanation for thsithis behaviour?

Consider the definition:

Clear[fun] fun[a_ + b_] := fun[a] + fun[b]; fun[a+b+c] (*fun[a] + fun[b] + fun[c]*) 

This works as expected. However, if we use a BlankSequence on "b":

Clear[fun] fun[a_ + b__] := fun[a] + fun[b]; fun[a + b + c] (*fun[a] + fun[b, c]*) 

it seems that BlankSequence eliminates the Plus in "b+c" and replaces it with Sequence. Has anybody a good explanation for thsi behaviour?

Consider the definition:

Clear[fun] fun[a_ + b_] := fun[a] + fun[b]; fun[a+b+c] (*fun[a] + fun[b] + fun[c]*) 

This works as expected. However, if we use a BlankSequence on "b":

Clear[fun] fun[a_ + b__] := fun[a] + fun[b]; fun[a + b + c] (*fun[a] + fun[b, c]*) 

it seems that BlankSequence eliminates the Plus in "b+c" and replaces it with Sequence. Has anybody a good explanation for this behaviour?

Source Link
Daniel Huber
  • 60.8k
  • 2
  • 25
  • 71

Pattern Matching BlankSequence

Consider the definition:

Clear[fun] fun[a_ + b_] := fun[a] + fun[b]; fun[a+b+c] (*fun[a] + fun[b] + fun[c]*) 

This works as expected. However, if we use a BlankSequence on "b":

Clear[fun] fun[a_ + b__] := fun[a] + fun[b]; fun[a + b + c] (*fun[a] + fun[b, c]*) 

it seems that BlankSequence eliminates the Plus in "b+c" and replaces it with Sequence. Has anybody a good explanation for thsi behaviour?