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

   Insert Struct into a sorted list

Arguments
   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

Type
   library(lists_of_structures)

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 --- Arguments are insufficiently instantiated
     5 --- Some argument or its components are of the wrong type
     6 --- 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
