Note that every message in paragram is a tuple, so in order to match any number of any objects, you should add a receiver for paragram.etc.
Let’s illustrate these rules by example.
In the table below, the first column contains a Python value that is used as a pattern. The second column contains Python values that match the pattern and the third column contains Python values that do not match the pattern.
Pattern | Matches | Non-Matches |
---|---|---|
Any | 'text', 13.7, (1, '', lambda: true) | |
'land shark' | 'land shark' | 'dolphin', 42, [] |
13.7 | 13.7 | 'text', 13.6, {'A': 14} |
int | 13, 42, 0 | 'text', 13.7, [] |
str | 'plumber', '' | 42, 0.9, lambda: True |
lambda x,y,z: x+y+z == 3 | (1, 1, 1), (3, 1, -1) | (3,), (1, 2, 3) |
(str, int) | ('shark', 42), ('dolphin', 0) | ['shark', 42], ('dolphin', 42, 0) |
(str, int, etc) | ('shark', 42), ('dolphin', 0, 1, 2, True) | ['shark', 42], ('dolphin', 42, 0) |
(str, 20, lambda x: x < 0) | ('shark', 20, -54.76), ('dolphin', 20, -1) | ('shark', 21, -6), (20, 20, -1), ('', 20) |
['A', str, str] | ['a', 'b', 'c', 'd'], ['a', 'b'] | ['C', 'B', 'A'], ['A'] |
[str, int] | ['dolphin', 42, 0], ['shark'] | [42, 0], ['dolphin', 42, 'shark'] |
[Any] | ['dolphin', 42, 0.9], [] | ('dolphin', 42, 0.9), 'shark' |
{'S': int, 19: str} | {'S': 3, 19: 'foo'}, {'S': -65, 19: 'bar', 'T': 'me'} | {'S': 'Charlie', 19: 'foo'}, {'S': 3} |