## `evalassign` -- assignment with evaluation of the left hand side

#### Introduction

`evalassign(`x, value, i`)` evaluates `x` with substitution depth `i` and assigns `value` to the result of the evaluation.

#### Call(s)

`evalassign(x, value, i)`
`evalassign(x, value)`

#### Parameters

`x` | - | an object that evaluates to a valid left hand side of an assignment
`value` | - | any MuPAD object
`i` | - | a nonnegative integer less than 2^31

#### Returns

`value`.

#### Related Functions

`:=`, `_assign`, `assign`, `assignElements`, `delete`, `eval`, `LEVEL`, `level`

#### Details

- `evalassign(`x, value, i`)` evaluates `value`, as usual. Then it evaluates `x` with substitution depth `i`, and finally it assigns the evaluation of `value` to the evaluation of `x`.

  The difference between `evalassign` and the assignment operator `:=` is that the latter does not evaluate its left hand side at all.

- As usual, the evaluation of `value` takes place with substitution depth given by `LEVEL`. By default, it is `1` within a procedure.

- See the help pages of `LEVEL` and `level` for the notion of substitution depth and for details about evaluation.

- The third argument is optional. The calls `evalassign(`x, value`)`, `evalassign(`x, value, 0`)`, `x := value`, and `_assign(x, value)` are all equivalent.

- The result of the evaluation of `x` must be a valid left hand side for an assignment. See the help page of `:=` for details.

- The second argument is not flattened. Hence it may also be a sequence. Cf. example 2.

#### Example 1

`evalassign` can be used in situations such as the following. Suppose that an identifier `a` has another identifier `b` as its value, and that we want to assign something to this value of `a`, not to `a` itself:

    >> delete a, b: a := b:
       evalassign(a, 100, 1): level(a, 1), a, b

                                    b, 100, 100

This would not have worked with the assignment operator `:=`, which does not evaluate its left hand side:

    >> delete a, b: a := b:
       a := 100: level(a, 1), a, b

                                    100, 100, b

#### Example 2

The second argument may also be a sequence:

    >> a := b:
       evalassign(a, (3,5), 1):
       b

                                       3, 5

#### Background

- The function `level` is used for the evaluation of `x`. Hence `i` may exceed the value of `LEVEL`.

- All special rules for `_assign` apply: see there on further details on indexed assignments, assignments to slots, and the `protect` mechanism.

#### Changes

- no changes

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