## `extop` -- the operands of a domain element

#### Introduction

`extop(`object`)` returns all operands of the domain element `object`.

`extop(`object, i`)` returns the `i`-th operand.

`extop(`object, i..j`)` returns the `i`-th to `j`-th operand.

#### Call(s)

`extop(object)`
`extop(object, i)`
`extop(object, i..j)`

#### Parameters

`object` | - | an arbitrary MuPAD object
`i, j` | - | nonnegative integers

#### Returns

a sequence of operands or the specified operand. `FAIL` is returned if no corresponding operand exists.

#### Related Functions

`DOM_DOMAIN`, `extnops`, `extsubsop`, `new`, `nops`, `op`, `subsop`

#### Details

- For objects of a basic data type such as expressions, sets, lists, tables, arrays etc., `extop` yields the same operands as the function `op`. See the corresponding documentation for details on operands. The main difference to the function `op` is that `extop` cannot be overloaded. Therefore, it guarantees direct access to the operands of the internal representation of elements of a library domain. Typically, `extop` is used in the implementation of the `"op"` method of a library domain that overloads the system's `op` function.
- A domain element consists of a reference to the corresponding domain and a sequence of values representing its contents. The function `extop` allows access to the domain and the operands of this internal data sequence.
- `extop(`object`)` returns a sequence of all internal operands except the 0-th one. This call is equivalent to `extop(`object, 1..extnops(object)`)`.
- `extop(`object, i`)` returns the `i`-th internal operand. In particular, the domain of the object is returned by `extop(`object, 0`)` if `object` is an element of a library domain. If `object` is an element of a kernel domain, the call `extop(`object, 0`)` is equivalent to `op(object, 0)`.
- `extop(`object, i..j`)` returns the `i`-th to `j`-th internal operands of `object` as an expression sequence; `i` and `j` must be nonnegative integers with `i` smaller or equal to `j`. This sequence is equivalent to ``extop(`object, k`)` $k = i..j`.
- `extop` returns `FAIL` if a specified operand does not exist. Cf. example 4.
- The operands of an expression sequence are its elements. Note that such sequences are not flattened by `extop`.
- `extop` is a function of the system kernel.

#### Example 1

We create a new domain `d` and use the function `new` to create an element of this type. Its internal data representation is the sequence of arguments passed to `new`:

    >> d := newDomain("demo"): e := new(d, 1, 2, 3): extop(e)

                                      1, 2, 3

Individual operands can be selected:

    >> extop(e, 2)

                                         2

Ranges of operands can be selected:

    >> extop(e, 1..2)

                                       1, 2

The 0-th operand of a domain element is its domain:

    >> extop(e, 0)

                                       demo

    >> delete d, e:

#### Example 2

First, a new domain `d` is defined via `newDomain`. The `"new"` method serves for creating elements of this type. The internal representation of the domain is a sequence of all arguments of this `"new"` method:

    >> d := newDomain("d"): d::new := () -> new(dom, args()):

The system's `op` function is overloaded by the following `"op"` method of this domain. It is to return the elements of a sorted copy of the internal data sequence. In the implementation of the `"op"` method, the function `extop` is used to access the internal data:

    >> d::op := proc(x, i = null())
                local internalData;
                begin internalData := extop(x);
                      op(sort([internalData]), i)
                end_proc:

Due to this overloading, `op` returns different operands than `extop`:

    >> e := d(3, 7, 1): op(e); extop(e)

                                      1, 3, 7

                                      3, 7, 1

    >> delete d, e:

#### Example 3

For kernel data types such as sets, lists etc., `extop` always returns the same operands as `op`:

    >> extop([a, b, c]) = op([a, b, c])

                               (a, b, c) = (a, b, c)

Expressions are of kernel data type `DOM_EXPR`, thus `extop(sin(x), 0)` is equivalent to `op(sin(x), 0)`:

    >> domtype(sin(x)), extop(sin(x), 0) = op(sin(x), 0)

                                DOM_EXPR, sin = sin

Expression sequences are not flattened:

    >> extop((1, 2, 3), 0), extop((1, 2, 3))

                                 _exprseq, 1, 2, 3

#### Example 4

Non-existing operands are returned as `FAIL`:

    >> extop([1, 2], 4),  extop([1, 2], 1..4)

                                    FAIL, FAIL

#### Changes

- `extop` now works on elements of kernel domains like `op`.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000