Questions tagged [rakudo]

Rakudo is a compiler for the Raku programming language running on the MoarVM virtual machine.

Rakudo is a Raku compiler running on the MoarVM, JVM and JavaScript.

Related links

189 questions
12
votes
1 answer

Why do different ways of calling Raku result in very different startup times?

I have v2020.12 of Rakudo installed on my computer and have also built v2020.12 from source. When profiling startup times, I noticed the following results: (these benchmarks use hyperfine, but I also got similar results with time). $ which…
codesections
  • 8,900
  • 16
  • 50
12
votes
1 answer

Is it possible to define a new operator in Raku and control its precedence?

Consider this new operator: sub infix:<*++>(\num1, \num2) { num1 * num2 + 1 } say (2 + 1 *++ 3); This code prints: 10 However, is it possible to control the precedence? Such it behaves like this: say (2 + (1 *++ 3)) without needing to use…
Julio
  • 5,208
  • 1
  • 13
  • 42
12
votes
2 answers

Understanding Raku's `&?BLOCK` compile-time variable

I really appreciate the Raku's &?BLOCK variable – it lets you recurse within an unnamed block, which can be extremely powerful. For example, here's a simple, inline, and anonymous factorial function: { when $_ ≤ 1 { 1 }; $_ × &?BLOCK($_ - 1)…
codesections
  • 8,900
  • 16
  • 50
12
votes
1 answer

How do you access private methods or attributes from outside the type they belong to?

In some rare cases where this would actually be acceptable, like in unit tests, you may want to get or set the value of a private attribute, or call a private method of a type where it shouldn't be possible. Is it really impossible? If not, how can…
Kaiepi
  • 3,230
  • 7
  • 27
11
votes
1 answer

Strange behavior when changing $*SCHEDULER after execution of external program

Description There is an example: #!/bin/env raku run 'raku', '-e', 'say "ok"'; exit 0; my $*SCHEDULER = ThreadPoolScheduler.new(max_threads => 128); On linux output is: ok Unhandled exception in code scheduled on thread 4 No such method 'cue' for…
fingolfin
  • 591
  • 9
11
votes
3 answers

Using NativeCall to call the C fn `erf` gets more precise output than `erf` in C

I have written a Raku script to call erf function in C standard library: use NativeCall; sub erf(num64) returns num64 is native { * }; say [0.5,1,2,3,4,-0.9].map: {erf($_.Num)}; The output of this script (0.5204998778130465 0.8427007929497149…
Suman Khanal
  • 3,079
  • 1
  • 17
  • 29
11
votes
3 answers

How to apply one signature test to multiple positionals

I wrote some code in https://github.com/p6steve/raku-Physics-Measure that looks for a Measure type in each maths operation and hands off the work to non-standard methods that adjust Unit and Error aspects alongside returning the new value: multi…
librasteve
  • 6,832
  • 8
  • 30
11
votes
2 answers

How to execute raku script from interpreter?

I open raku/rakudo/perl6 thus: con@V:~/Scripts/perl6$ perl6 To exit type 'exit' or '^D' > Is the above environment called the "interpreter"? I have been searching forever, and I cannot find what it's called. How can I execute a rakudo script like…
con
  • 5,767
  • 8
  • 33
  • 62
11
votes
2 answers

How to get a "help" functionality in REPL

When I use REPL, I sometimes need to look up how a function functions e.g. splice. I usually go to the documentation website. But I don't always have internet and it'd be good if I could write help("splice") or something (e.g. splice?) in the REPL…
user15750474
11
votes
2 answers

Actually CATCHing exceptions without creating GOTO

Looking over my Raku code, I've realized that I pretty much never use CATCH blocks to actually catch/handle error. Instead, I handle errors with try blocks and testing for undefined values; the only thing I use CATCH blocks for is to log errors…
codesections
  • 8,900
  • 16
  • 50
11
votes
1 answer

`does` versus `but` operators when mixing in a Role into an object in Raku

If I have a Role R defined as: role R { method answer { 42 } } What is the difference (if any) between these two lines: my $a = 'question' does R; my $b = 'question' but R; They appear very similar: say $a.answer; # OUTPUT: «42» say $b.answer; …
codesections
  • 8,900
  • 16
  • 50
11
votes
2 answers

How to use a wrapper script for a Raku CLI

I am wondering what steps, (such as shebang lines and wrapper scripts) are recommended when creating a CLI application in Raku. I am interested in info both for scripts that will be installed with Zef and those that will be distributed…
codesections
  • 8,900
  • 16
  • 50
11
votes
1 answer

Why can't I name a sigilless variable v+digit?

Running the following simple code, checking the behaviour of sigilless variables, produces a strange error: use v6.d; # Rakudo Star 2020.05.01 (Windows) sub test ($p) { say $p; } my \v1 = 1; say v1; # v1 (ERROR) test(v1); # v1 (ERROR) my…
jakar
  • 1,701
  • 5
  • 14
11
votes
3 answers

Why does Rakudo dd return Nil for a typed and assigned scalar?

The below is a REPL session using Rakudo. > my Int $x = 1 1 > dd $x Int $x = 1 Nil Why is there a Nil on the second line of the output of dd?
Ross Attrill
  • 2,594
  • 1
  • 22
  • 31
11
votes
1 answer

How to benchmark Raku?

I regularly follow the GitHub Rakudo repository to see what changes are going on in the Rakudo compiler. I sometimes see commits where the individual functions are sped up by certain percentage, and times like the image below. What is the workflow…
Suman Khanal
  • 3,079
  • 1
  • 17
  • 29
1
2
3
12 13