Refs
Refs are pointers to local variables or parameters. Refs look and behave
exactly like the value contained in the variable referred to. In
assignments, the ampersand (&) is added before an assignable
expression to indicate that the value returned by the expression should be treated as
a ref and the contents of the referred variable should be changed.
Refs are created by adding an ampersand before the local variable or parameter reference.
Here are methods to investigate refs:
- ``
anvil.lang.deref(ref, derefAll=false)´´
-
Takes a reference and returns the referenced value; or, if the second parameter is true, it follows the reference chain until the first non-ref value is encountered and returns that.
- ``
anvil.lang.ref()´´
-
Creates and returns programmable ref from class instance, which can have
the two callbacks,
``
_getRef()´´ and
``_setRef(value)´´, for emulating the ref accessed and assignments.
- ``
anvil.lang.reveal(ref)´´
-
Reveals and returns the ref provider (class instance) from the ref created
with the
anvil.lang.ref function above.
ref-expr := "&" identifierlocal-or-parameter
Add a note
|