Navigation
Synopsis The difference between two lists.
Syntax Exp1 - Exp2
Types
Exp1 Exp2 Exp1 - Exp2
list[T1] list[T2] list[lub(T1,T2)]
list[T1] T2 list[lub(T1,T2)]
Description If both Exp1 and Exp2 have a list as value, the result is the difference of these two list values. If Exp2 does not have a list as value, it is first converted to a list before the difference is computed. The difference is computed by taking the successive elements of the second list and removing the first occurrence of that element in the first list.
Examples
rascal>[1, 2, 3, 4] - [1, 2, 3];
list[int]: [4]
rascal>[1, 2, 3, 4] - [3];
list[int]: [1,2,4]
rascal>[1, 2, 3, 4] - 3;
list[int]: [1,2,4]
rascal>[1, 2, 3, 4] - [5, 6, 7];
list[int]: [1,2,3,4]
rascal>[1, 2, 3, 1, 2, 3] - [1];
list[int]: [2,3,1,2,3]
rascal>[1, 2, 3, 1, 2, 3] - [1, 2];
list[int]: [3,1,2,3]

Questions
Question [1]. When you compute the difference of two lists, the number of elements in the result is always:




Question [2].
The type of ["R2-D2", "Raspberry", "Pincess Leia"] - ["Isolder"] is

Question [3].
[69,5,52,17,67] - [23,80,43,41,67,1] == 



Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.