September 2013
Intermediate to advanced
548 pages
12h 25m
English
++ and -- are infix operators for list addition and
subtraction.
A ++ B adds (that is, appends) A and B.
A -- B subtracts the list B from the list A.
Subtraction means that every element in B is removed from A.
Note that if some symbol X occurs only K times in B,
then only the first K occurrences of X in A will be
removed.
Here are some examples:
| | 1> [1,2,3] ++ [4,5,6]. |
| | [1,2,3,4,5,6] |
| | 2> [a,b,c,1,d,e,1,x,y,1] -- [1]. |
| | [a,b,c,d,e,1,x,y,1] |
| | 3> [a,b,c,1,d,e,1,x,y,1] -- [1,1]. |
| | [a,b,c,d,e,x,y,1] |
| | 4> [a,b,c,1,d,e,1,x,y,1] -- [1,1,1]. |
| | [a,b,c,d,e,x,y] |
| | 5> [a,b,c,1,d,e,1,x,y,1] -- [1,1,1,1]. |
| | [a,b,c,d,e,x,y] |
++ can also be used in patterns. When matching strings,
we can write patterns such as the following:
| |
Read now
Unlock full access