This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Counts slot assignments

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.




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.


Example 1

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


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

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

Now the counter has the value 1:


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:

Now we add a "foo" slot to bar:

bar::foo := x -> 4:

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")):
bar::foo := x -> 5:

delete foo, bar:



Any MuPAD® object

Return Values

Non-negative number of type DOM_INT.

See Also

MuPAD Functions

Was this topic helpful?