List Insert
rascal-0.34.0
Synopsis
add an element in front of a list
Types
//
Exp₁ | Exp₂ | Exp₁ + Exp₂ |
---|---|---|
T₁ | list[T₂] | list[lub(T₁,T₂)] |
Description
The +
operator can insert an element in front of a list. Note that +
is one of the Operators that is overloaded, it is also Concatenation and Append for example.
Examples
rascal>1 + []
list[int]: [1]
rascal>1 + [2]
list[int]: [1,2]
rascal>1 + [2,3]
list[int]: [1,2,3]
Pitfalls
- If the first operand before the
+
is a list,+
acts as Concatenation and not as Insert
This is concatenation:
rascal>[1] + [2]
list[int]: [1,2]
To insert a list as an element, use extra brackets:
rascal>[[1]] + [2]
list[value]: [
[1],
2
]