Home > Raku > The mysterious infix

The mysterious infix

Vadim Belman informed us that he started a module for writing GUI apps in the console. That gave me a massive flashback to the nineties. Looking at the example code got me the next flashback. If you need a button you need to subclass. In fact if you need anything you need to subclass. In a dynamic language with lexical scoping that might actually work.

Looking at the code one can see lots and lots of Raku features to be used. I even found this gem.

$!id = ++⚛$sequence;

That’s clearly not from the nineties. Back then real programmers could get anything done with just one core!

There are a few examples Vadim wrote for us and the interface for his module look pretty 90ish again. Which made me think for a while how a “modern” interface could look like. In the process I didn’t come up with something better but stepped on a bug.

As it turns out is looser(&infix:<:>)should be in %categorically-won't-work. There are quite a few things that wont work but are not documented. Luckily there is a workaround for defining a new operator that got looser precedence than the colon that separates a method name from its arguments.

sub infix:«add»(Parent:D \p, Child:D \c --> Parent:D) is equiv(&infix:<and>) {
    p.add-child: c;
    p
}

$p add Child.new: :birthday("april") add Child.new: :birthday("december");

All we need to do is to be equally loose then and.

The usefulness of an add operator appeared questionalbe to me until I realised that feed operators are not. Yet Raku does not make much use of them. I believe the following should be dwimmy.

my $c = Channel.new;
$c <== "foo";

Raku is still a bit incomplete. But fear not we are only at e!

Categories: Raku
  1. vrurg
    May 25, 2020 at 04:18

    I have a note about the flashback into 90s on reddit.

  1. June 1, 2020 at 13:39

Leave a comment