[ library(lists_of_structures) | Reference Manual | Alphabetic Index ]
inserta(+Key, +Struct, +Old, -New)
Insert Struct into a sorted list
- Key argument position (non-negative integer, or list of those)
- Ordered list of structures
- Ordered list of structures, or variable
Inserts the compound term Struct into the ordered list Old, giving New.
The lists are both in ascending order (according to their elements' Key'th
argument), and may contain duplicates. If Old already contains elements
with the same key as Struct, then Struct is inserted before those.
The list New is always one element longer than the list Old.
Modes and Determinism
- inserta(+, +, +, -) is det
- (4) instantiation fault
- Arguments are insufficiently instantiated
- (5) type error
- Some argument or its components are of the wrong type
- (6) out of range
- Some structure does not have a Key'th argument
?- inserta(1, f(2,new), [f(1,a),f(2,b),f(2,c),f(3,d)], New).
New = [f(1,a), f(2,new), f(2,b), f(2,c), f(3,d)]
Yes (0.00s cpu)
merge / 5, sort / 4