The 'xx' operator is interesting in that this:
(^100).pick xx 10
produces a list of 10 random Int's rather than one random Int repeated 10 times as a list.
Is the operator handled as a special case by the compiler? Or is it really just another sub that we can define ourselves too? (If so, I'd be very interested to know how...)
Thanks
Yes, this is one of a range of operators that currently exist as special forms in the compiler. Other examples include ||
and &&
, which only evaluate the right hand side depending on the boolification of the left hand side.
At present, there's not a way to define such an operator yourself (or at least, not an officially supported one; if prepared to tinker in compiler internals all things are possible). However, macros - planned for the next major Raku language version - will enable this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With