[ library(lists_of_structures) | Reference Manual | Alphabetic Index ]

# insertz(+Key, +Struct, +Old, -New)

Insert Struct into a sorted list

Key
  Key argument position (non-negative integer, or list of those)
Struct
  Structure
Old
  Ordered list of structures
New
  Ordered list of structures, or variable

## Description

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 after those.

The list New is always one element longer than the list Old.

### Modes and Determinism

- insertz(+, +, +, -) is det

### Exceptions

(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

## Examples

        ?- insertz(1, f(2,new), [f(1,a),f(2,b),f(2,c),f(3,d)], New).
        New = [f(1,a), f(2,b), f(2,c), f(2,new), f(3,d)]
        Yes (0.00s cpu)

## See Also

merge / 5, sort / 4