slotAssignCounter

Counts slot assignments

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

slotAssignCounter(key)

Description

slotAssignCounter(key) returns the number of slot assignments with the key key since the initialization of the counter. The counter for key is initialized with 0 on the first call of slotAssignCounter(key). Previous assignments with the key key are not counted.. This function serves a highly technical purpose. Usually, there should be no need for a user to call this function.

slotAssignCounter only counts assignments to slots of domains and function environments.

slotAssignCounter was introduced as a dependency check function for prog::remember. See Example 2.

Examples

Example 1

We initialize slot assignment counting of the slot "foo":

slotAssignCounter("foo")

Then we define a function f with a slot "foo":

f := funcenv(f):
f::foo := bar:

Now the counter has the value 1:

slotAssignCounter("foo")

Example 2

Here we define a recursing function foo which overloads for domain elements. The function remembers computed values with prog::remember:

foo := x -> (if x::dom::foo <> FAIL then return(x::dom::foo(x)) end_if;
             if x = op(x) then procname(x) else map(x, foo) end_if):
foo := prog::remember(foo):

Then we define a domain bar which does not overload the slot "foo":

bar := newDomain("bar"):
bar::new := x -> new(bar, x):
bar::print := x -> hold(bar)(extop(x)):
bar::op := id:
foo(bar(2))

Now we add a "foo" slot to bar:

bar::foo := x -> 4:
foo(bar(2))

The new slot was not used, because foo took the result from its remember table. If we use a dependency function with slotAssignCounter in prog::remember, we can make foo aware of changes in "foo"-slots of other functions and domains:

foo := x -> (if x::dom::foo <> FAIL then return(x::dom::foo(x)) end_if;
             if x = op(x) then x else map(x, foo) end_if):
foo := prog::remember(foo, () -> slotAssignCounter("foo")):
foo(bar(2));
bar::foo := x -> 5:
foo(bar(2))

delete foo, bar:

Parameters

key

Any MuPAD® object

Return Values

Non-negative number of type DOM_INT.

See Also

MuPAD Functions

Was this topic helpful?