Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the xx operator in Raku able to delay the evaluation of its left-hand side code operand?

Tags:

raku

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

like image 585
cowbaymoo Avatar asked Apr 20 '20 03:04

cowbaymoo


1 Answers

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.

like image 183
Jonathan Worthington Avatar answered Oct 22 '22 07:10

Jonathan Worthington