the inter-realm changes, in a nutshell

because everyone seems kind of confused right now

over the past few weeks, we merged #4060, a pr which "creatively" addresses the problem of having safe and understandable rules for how realms interact with other realm's objects.

this note is meant to be short and be a "cheatsheet" of rules for writing inter-realm code; but do read the gno-interrealm document for a more comprehensive explanation.

  • there is a notion of "active realm", which doesn't necessarily match the code where it's defined. a realm needs to be switched explicitly.
  • only the active realm is able to change the value of the global variables in that package.
  • a function must be defined with crossing() if it has to be called switching realms. when it is defined as crossing(), it must be called using cross(fn)(...) (unless it's called within the same package, in which case it's not necessary)
  • crossing() cannot be used in packages.
  • when calling a method, it implicitly switches to the realm of that method (the realm is, in order, 1. where it is stored or 2. the realm calling it (if unreal, ie. not persisted through finalization yet)). the switch is "implicit" in the sense that it is able to change the value of the variables and of the receiver, BUT CurrentRealm and PreviousRealm don't change from the caller. the rationale is to always be able to modify the receiver from a method.
  • a method may still be defined as crossing(), in which case it needs to be called with cross().

these are likely to change again soon, but hopefully this can help us in the short-term.

Subscribe to diary of a gnome

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe