Why can readonly array attributes be modified on a Raku class, but on the other hand, scalars cannot be modified?
How can I make @.baz "readonly"?
class Boo {
has $.bar;
has @.baz;
};
my $boo = Boo.new;
$boo.baz = (1, 2); # works ... ?
say…
Consider
.say for (1,2,2).rotor(2=>-1).map( -> ($a, $b) { $a - $b })
which works as expected. However,
.say for (1,2,2).pairs.rotor(2=>-1).map( -> ($a, $b) { $a.value - $b.value })
throws
Too few positionals passed to ''; expected 2…
I'm using macOS Catalina and trying to execute a simple command raku -e "use Cro::HTTP::Route". I will get a message [1] 19228 abort raku in the Zsh shell or Abort trap: 6 in the Bash shell. I face the same issue when using an OpenSSL module like…
Please consider the code below. Why is the output of this is "BABABA" and not "AAABAA" / "AABAAAB"? Shouldn't the two supplies run in parallel and the whenever fire immedeatly when there is an event in any of them?
my $i = 0;
my $supply1 = supply {…
While finalizing my upcoming Raku Advent Calendar post on sigils, I decided to double-check my understanding of the type constraints that sigils create. The docs describe sigil type constraints with the table
below:
Based on this table (and my…
The Raku docs describe ::?CLASS as a compile-time variable that answers "Which class am I in?". Then, a couple of paragraphs later, it mentions $?CLASS, and says that it answers "Which class am I in? (as variable)".
What's the difference between…
I have read an article by Jonathan Worthington about meta programming.
There he writes:
Do do this, we stick it in the EXPORTHOW module, under the name
“class”. The importer pays special attention to this module, if it
exists.
At he same time here…
I have two files main.raku and TestMod.rakumod in a directory C:\Users\suman.
TestMod.rakumod
unit module TestMod;
sub add($a, $b) is export {
$a + $b
}
main.raku
use lib $*PROGRAM.dirname;
use TestMod;
say add(8,9)
I want to call some…
I am trying to sum a list of lists in Raku. Example taken from here:
my $arr = ([1e50, 1, -1e50] xx 1000);
say (flat |$arr).sum; # output 0
# https://docs.raku.org/language/operators#infix_xx
# https://docs.raku.org/routine/flat
It outputs 0…
Raku's state declarator can be used to give a subroutine or other block its own local state that persists across multiple invocations of the function:
sub f { state $n++ }
say f; # OUTPUT: «0»
say f; # OUTPUT: «1»
say f; # OUTPUT: «2»
I'm aware of…
The docs say that fmt
Returns a string where each element in the list has been formatted according to $format [the first argument] and where each element is separated by $separator [the second argument].
Based on that description, I expected to be…
The docs state that "The simplest way to run a block where it cannot be a stand-alone statement is by writing do before it" and provide the following example:
# This dies half of the time
do { say "Heads I win, tails I die."; Bool.pick } or die;…
I wrote this code for this weeks challenge to produce ugly numbers.
sub factors( $n ) {
if $n > 1 {
$_, |factors $n div $_
given ( grep $n %% *, 2..* ).first } }
.say for ( 1, |grep *.&factors.all ∈ ( 2, 3, 5 ), 2..* )[^150];
This…
The following program correctly fails to compile:
sub f(Int $a) { my Str $b = $a }
say f 42;
say f 'foo';
Specifically, line 3 causes a compilation error (with a ===SORRY!=== error message); this error occurs before line 2 is executed, so the type…