nreplace, nreplace_equal

Gamma: Version 4.0
Prev |  | Next

# `nreplace`, `nreplace_equal`

`nreplace`, `nreplace_equal` -- replace elements in a list.

## Syntax

    nreplace (new_s_exp, old_s_exp, list)
    nreplace_equal (new_s_exp, old_s_exp, list)

## Arguments

`new_s_exp`

  The new expression to be inserted into the list.

`old_s_exp`

  The expression in the list to be replaced.

`list`

  A list.

## Returns

The `list`, with all occurrences of `old_s_exp` destructively replaced by `new_s_exp`.

## Description

`nreplace` traverses the `list`, replacing any element which is `eq` to `old_s_exp` with `new_s_exp`. `nreplace_equal` uses `equal` as its comparison function.

## Example

        Gamma> R = list (#f, nil, 5, #ftg);
        (f nil 5 ftg)
        Gamma> nreplace(#h, #ftg, R);
        (f nil 5 h)

        Gamma> x = list(1,2,3,1,6,7);
        (1 2 3 1 6 7)
        Gamma> nreplace(4,1,x);
        (1 2 3 1 6 7)
        Gamma> nreplace_equal(4,1,x);
        (4 2 3 4 6 7)
        Gamma> x;
        (4 2 3 4 6 7)
        Gamma>

## See Also

`remove`, `nremove`

Prev | Home | Next
`nremove` | Up | `nth_car`, `nth_cdr`

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