Hacker News new | ask | show | jobs
by gfldex 1582 days ago
As a sister language of Perl, Raku can do the same trick.

    constant &s = (now.DateTime.day-of-week == 7) ?? sub () {} !! sub (|) {};
    constant c = s(42);
Constants are evaluated at compile time. Here we define a sub that takes no argument or any number of arguments depending on the day of the week (In Raku we start at 1 for monday to avoid ending the universe by deviding by 0). While binding the return value of s(42) to a constant we force execution of that sub at compile time. Thusly, we create a program that can not be executed when compiled on sundays. This is reasonalbe, because by heavenly mandate we are bound to rest on that day.

Modules are precompiled, programs are not (yet). So to make this really depend on the day of compilation we have to put it into a module (for now).