Previous Page Next Page Contents

append -- add elements to a list

Introduction

append(l, object) adds object to the list l.

Call(s)

append(l, object1, object2, ...)

Parameters

l - a list
object1, object2, ... - arbitrary MuPAD objects

Returns

the extended list.

Overloadable:

l

Related Functions

_concat, _index, DOM_LIST, op

Details

Example 1

The function append adds new elements to the end of a list:

>> append([a, b], c, d)
                               [a, b, c, d]

If no new elements are given, the first argument is returned unmodified:

>> l := [a, b]: append(l)
                                  [a, b]

The first argument may be an empty list:

>> append([], c)
                                    [c]

Example 2

The function append always returns a new object. The first argument remains unchanged:

>> l := [a, b]: append(l, c, d), l
                           [a, b, c, d], [a, b]

Example 3

Users can overload append for their own domains. For illustration, we create a new domain T and supply it with an "append" slot, which simply adds the remaining arguments to the internal operands of its first argument:

>> T := newDomain("T"):
   T::append := x -> new(T, extop(x), args(2..args(0))):

If we now call append with an object of domain type T, the slot routine T::append is invoked:

>> e := new(T, 1, 2): append(e, 3)
                              new(T, 1, 2, 3)

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000