6.26. kink/VARREF

6.26.1. type varref

`varref` is a variable reference, which is a value that represents a variable.

A `varref` is a tuple of (Owner, Sym), where `Owner` is the owner value of the variable, and `Sym` is the symbol of the variable.

`varref` is a subtype of `plain_param`. See kink/param/PLAIN_PARAM.

6.26.1.1. Varref.owner

`owner` returns `Owner` of `Varref`.

Example

6.26.1.2. Varref.sym

`sym` returns a `str` value of `Sym` of `Varref`.

Example

6.26.1.3. Varref <- Content

`<-` operator, or `op_store` method, performs variable-store operation for the variable represented by `Varref`, with `Content` as the content of the variable.

Example

6.26.1.4. Varref.load

`load` performs variable-load operation for the variable represented by `Varref`, and returns the content value of the variable.

Precondition

The content of the variable must not be empty.

Example

6.26.1.5. Varref.any?

`any?` performs variable-load operation for the variable represented by `Varref`, and returns whether the content is not empty.

Example

6.26.1.6. Varref.require_from(Prefix)

`require_from` loads a module then stores the module to the variable.

Calling this method is equivalent to calling `Varref <- MOD.require(Prefix + Varref.sym)`.

Precondition

`Prefix` must be a `str`.

Example

6.26.1.7. Varref.rest

`rest` returns a `rest_param` backed by the variable.

`pass_rest(Rest_args)` method of the result `rest_param` stores `Rest_args` to the variable.

See also kink/param/REST_PARAM

Example

6.26.1.8. Varref.opt

`opt` makes an `opt_param` backed by the variable.

`pass_arg(Arg)` method of the result `opt_param` stores a singleton vector `[Arg]` to the variable.

`pass_nothing` method of the result opt_param stores an empty vector to the variable.

See also kink/param/OPT_PARAM

Example

6.26.2. VARREF.new(Owner Sym)

`new` returns a `varref` (Owner, Sym).

Precondition

`Sym` must be a `str`.

Example

6.26.3. VARREF.is?(Val)

`is?` returns whether `Val` is a `varref`.