std-setnth


Synopsis

(std-setnth <new> <i> <lst) ; replace by position

(std-rplace <lst> <i> <new>) ; old depricated name

Description

STD-SETNTH replaces the i'th elementwith new. It is used to change certain elements only at a certain position in the list, often in conjunction with STD-POSITION. It is not destructive, it always returns a copy. It is the counterpart of the function NTH.

SUBST will replace all matching elements by value, STD-SETNTH only one at the given position.

STD-RPLACE is the old depricated name, with reverse argument ordering.

Exceptional Situations

If the index i is invalid (out of range), the original list is returned.

No error is signalled and no elements are added to the list!

Examples

;; change first

(std-setnth 'new 0 '(0 1 2)) 	=> (NEW 1 2)

;; change last

(std-setnth 'new 2 '(0 1 2)) 	=> (0 1 NEW)

;; no element added

(std-setnth 'new 3 '(0 1 2)) 	=> (0 1 2)

Arguments

new: any lisp expression.

i: an integer number. Should be between 0 and (1- (length lst)) to modify the list argument.

lst: any proper list.

Return Value

A list.

Side Effects

None.

Module

(std-require 'STDLIST)

Defined in STDLIST