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

# args(+Key, +Structs, -Args)

Extract arguments from a list of structures

Key
  Key argument position (non-negative integer, or list of those)
Structs
  List of structures
Args
  Variable, or list of arguments

## Description

Structs is a list of structures, and Args is a list of the Key'th arguments of these structures.

This is equivalent to either

        maplist(arg(Key), Structs, Args)

or

        ( foreach(S,Structs), foreach(A,Args), param(Key) do arg(Key,S,A) )

### Modes and Determinism

- args(+, +, -) is det

### Exceptions

(4) instantiation fault
  Structs is insufficiently instantiated
(6) out of range
  Some structure in Structs does not have a Key'th argument

## Examples

        ?- args(2, [f(3,a),f(2,b),f(1,c)], Args).
        Args = [a,b,c]
        yes

        % extract keys from pairs
        ?- args(1, [a-1,a-2,b-2,c-2,c-5], Keys).
        Keys = [a,a,b,c,c]
        yes

        % extract values from pairs
        ?- args(2, [a-1,a-2,b-2,c-2,c-5], Values).
        Values = [1,2,2,2,5]
        yes

## See Also

arg / 3