Ulocal()

From TinyMUX
Revision as of 01:39, 29 November 2010 by Ihavenomouth (talk | contribs) (New page: Category:Functions FUNCTION: {{Function|ulocal([<obj>/]<attr>[,<arg>]...)}} The ulocal() function is almost identical to u() in function: it evaluates an [[attr...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


FUNCTION: ulocal([<obj>/]<attr>[,<arg>]...)

The ulocal() function is almost identical to u() in function: it evaluates an attribute, either from the object performing the function, or another object that you control or has the same owner as you, passing in arguments and returning the result. When evaluating the fetched attribute, %# refers to the original enactor and not the 'calling' object; 'me' refers to the object that supplied the attribute.

However, unlike the u() function, the global registers r(0) through r(9) and r(A) through r(Z) (%q0 - %q9, %qA - %qZ) are preserved in their initial state. This means that functions "below" the level of the u() can reset global registers for temporary calculations, without needing to worry about "clobbering" the original values.

This makes ulocal() particularly useful for global or shared code which calls arbitrary u() functions, where global register values need to be preserved from accidental user clobbering.

Example

> &FRUIT me=apples bananas oranges pears
> &SUB-FUNCTION me=[setq(0,v(FRUIT))][extract(%q0,match(%q0,%0),1)]
> &TOP-FUNCTION me=[setq(0,are delicious!)][ulocal(SUB-FUNCTION,%0)] %q0
> say u(TOP-FUNCTION,b*)
You say, "bananas are delicious!"


If SUB-FUNCTION had been called with u() instead of ulocal():
> &TOP-FUNCTION me=[setq(0,are delicious!)][u(SUB-FUNCTION,%0)] %q0
> say u(TOP-FUNCTION,b*)
You say, "bananas apples bananas oranges pears"

In this second example, in SUB-FUNCTION, %q0 was set to "apples bananas oranges pears", so that when the u() "returned" and TOP-FUNCTION evaluated %q0, this is what was printed. In the first example, ulocal() reset the value of %q0 to its original "are delicious!"

Related Topics

u(), setq(), r()