Home > Raku > Santa is pseudo packaging

Santa is pseudo packaging

Santa needs to know where all the chimneys are. Thanks to schedule constraints, a single subroutine call has to do to query multies defined in a bunch of modules.

use v6;

use NSA;
use SIS;
use BND;

sub chimneys {
     do for &chimney.candidates {

This is not very elegant. The sub chimneys should be defined in one of the modules. Since the modules are independent the order of the use-statements must not matter. Simply exporting the same symbol by each module would result in a compile time error. We can place a guard in PROCESS and export only if that guard is not True.

unit module NSA;

multi sub chimney is export {
     # super secret code goes here

sub EXPORT {
    sub chimneys {
        do for &CLIENT::chimney.candidates {

    my %ret;
    if ! try $PROCESS::SANTA-SPY {
        my $PROCESS::SANTA-SPY = True;
        %ret = '&chimneys' => &chimneys;


When we copy the EXPORT sub into each spy module, Santa does not have to worry about the order of use-statements. Also, the authors of those modules don’t need any coordination when extending their spying. This is important because spooks are incapable to work together not just at Christmas. In the sub chimneys we have to use the pseudo package CLIENT because in each module only one candidate of the multi chimney is visible.

Now Santa can find every single package target without getting near anybody to ask for directions. After all, keeping your distance is an important skill these days.

Categories: Raku
  1. December 7, 2020 at 22:52

    I wouldn’t recommend returning a hash from EXPORT. Values of the Associative returned by the sub are installed into the consuming namespace as-is. Because Hash containerize its values you get all symbols installed as scalars, no exception for subs. So, in fact, your &chimneys will end up being $&chimneys.

    The right thing to do is to use a Map which preserves the original containerization of the values.

  1. December 7, 2020 at 20:08

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: