nth_car, nth_cdr

Gamma: Version 4.0
Prev |  | Next

# `nth_car`, `nth_cdr`

`nth_car`, `nth_cdr` -- iteratively apply the `car` and `cdr` functions to a list.

## Syntax

    nth_car (list, number)
    nth_cdr (list, number)

## Arguments

`list`

  Any list.

`number`

  The number of cars (or cdrs) to apply to the list argument. Non-integers are rounded down. Non-numbers are treated as zero.

## Returns

An element of the `list`, or nil.

## Description

The `nth_car` and `nth_cdr` functions iteratively apply the `car` and `cdr` functions to a list. If the list argument is not a list, or if the result of any subsequent application of `car` or `cdr` is not a list, the result is nil. If the number of applications is less than or equal to 0, the result is the original list.

## Example

        Gamma> c = list (list(list(list(4,5))));
        ((((4 5))))
        Gamma> nth_car(c,2);
        ((4 5))
        Gamma> nth_car(c,4);
        4

        Gamma> b = list (6,7,8,9,10);
        (6 7 8 9 10)
        Gamma> nth_cdr (b,2);
        (8 9 10)
        Gamma> nth_cdr(b,5);
        nil
        Gamma> nth_cdr(b,4);
        (10)
        Gamma>

## See Also

`cons`, `list`, `car`, `cdr`

Prev | Home | Next
`nreplace`, `nreplace_equal` | Up | `remove`

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.