R/MRatCalcpowered by RiX

RiX walkthrough 10 d

Extend existing types

Add collision-safe receiver methods without patching individual values.

Register a receiver-first method

.RegisterMethod is a trusted system capability for extending an existing semantic or runtime type. The registered function receives the method's value as its first argument:

Runnable RiX

The registration changes method lookup, not either rational value or the RatMath JavaScript class behind it. obj.Method(arg) is receiver-first sugar for calling the registered function with obj followed by arg.

Accept ordinary method arguments

Arguments after the receiver are passed through in order. This extension wraps an existing exact rational operation in domain-specific vocabulary:

Runnable RiX

Use symbols such as :Rational and :Integer to name the target type. Choose a target narrowly enough that the method's contract is true for every matching receiver.

Treat collisions as errors

Built-in prototypes are frozen. Registering Numerator on Rational, for example, is rejected because that method already exists. A second registration of the same type and name is also rejected instead of letting plugin load order silently change behavior.

That means extension names are part of a plugin's public API. Prefer a precise name, and let a collision stop plugin loading so the conflict can be resolved explicitly.

Use plugin-owned extensions

Plugins normally perform registration while their mount is loading. Their methods are available only where that owning plugin mount is visible. The bundled radix plugin, for example, adds exact-number methods:

Runnable RiX

The float plugin similarly adds the explicit Float() conversion to integers and rationals. Loading a plugin therefore makes both its command namespace and its documented receiver methods available together.

Keep going

Open the plugin tutorials to see method registration used behind public APIs, or return to the package-design capstone to plan capability and trust boundaries for a larger extension.