[ Reference Manual | Alphabetic Index ]

# library(lists_of_structures)

Operations on lists of structures [more]

## Predicates

> args(+Key, +Structs, -Args)
>   Extract arguments from a list of structures
> group_by_key(+Key, +Structs, -Grouped)
>   Partition a list into sublists by key
> group_with_key(+Key, +Structs, -Grouped)
>   Partition a list into sublists by key
> inserta(+Key, +Struct, +Old, -New)
>   Insert Struct into a sorted list
> insertz(+Key, +Struct, +Old, -New)
>   Insert Struct into a sorted list
> lists_structs(?Lists, ?Structs)
>   Mapping between a structure of lists and a list of structures
> same_key_prefix(+Key, +All, -KeyVal, -Prefix, -Rest)
>   Get the maximum prefix of a list with identical key values
> separate_by_key(+Key, +Value, +All, -Matches, -Others)
>   Partition the elements of a list according to a key value
> terms_functor(?Structs, ?Length, ?Name, ?Arity)
>   All list elements have the given functor or atomic value
> update(+Key, +Struct, +Old, -New)
>   Incorporate Struct into a duplicate-free sorted list

## Description

This library contains predicates that operate on lists of structures, in particular structures where one argument can be considered a `key'. Such lists are very common, and often occur in sorted form.

The ECLiPSe kernel and other libraries support such lists as well, e.g.

- the sorting built-ins (sort/4, merge/5)
- hash:list_to_hash/4 for turning such lists into hash tables

If you have declared your structures using the :- local(struct(...)) declaration, then you can use field names to identify the key arguments in all these predicates, e.g.

        :- local struct(emp(name,age,salary)).

        ?- Emps = [emp{name:joe,salary:100}, emp{name:bob,salary:200}],
           sort(salary of emp, >=, Emps, Descending),
           args(name of emp, Descending, Names).

        Emps = [emp(joe, _, 100), emp(bob, _, 200)]
        Descending = [emp(bob, _, 200), emp(joe, _, 100)]
        Names = [bob, joe]
        yes

## About

- Author: Joachim Schimpf
- Copyright © Joachim Schimpf, 2013
- Date: $Date: 2015/04/08 17:48:57 $

## See Also

hash : list_to_hash / 4, sort / 4, merge / 5, struct / 1

Generated from lists_of_structures.eci on 2020-02-26 22:26