Skip to main content

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

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
]