[ library(lists_of_structures) | Reference Manual | Alphabetic Index ]
update(+Key, +Struct, +Old, -New)
Incorporate Struct into a duplicate-free sorted list
- Key
- Key argument position (non-negative integer, or list of those)
- Struct
- Structure
- Old
- Strictly ordered list of structures
- New
- Strictly ordered list of structures, or variable
Description
Inserts the compound term Struct into the ordered list Old, giving New.
The lists are both in strictly ascending order (according to their
elements' Key'th argument), i.e. without duplicates. If Old already
contains an element with the same key as Struct, then Struct replaces
this existing element. Otherwise, Struct is inserted at the correct
position to maintain the list order.
The list New is either of the same length as Old, or one longer.
Modes and Determinism
- update(+, +, +, -) 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
?- update(1, f(2,b), [f(1,a),f(3,c)], New).
New = [f(1,a), f(2,b), f(3,c)]
Yes (0.00s cpu)
?- update(1, f(2,new), [f(1,a),f(2,b),f(3,c)], New).
New = [f(1,a), f(2,new), f(3,c)]
Yes (0.00s cpu)
See Also
merge / 5, sort / 4