Questions tagged [rakudo]
Rakudo is a compiler for the Raku programming language running on the MoarVM virtual machine.
185
questions
8
votes
2
answers
92
views
Error install Inline::Perl5 with Zef (Raku)
I'm trying to install Raku on a Debian 11 x64. I never installed it before (perl5 too)
It's a server with some Perl5 scripts, and I want to "use" it in Raku with the Inline::Perl5 (also I ...
8
votes
2
answers
123
views
Why is my %h is List = 1,2; a valid assignment?
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 ...
7
votes
2
answers
107
views
How to slip gather-take in lazy manner into map?
I need to construct following flow:
Accept list of file names
Extract multiple lines from those files
Process those lines
However I have no idea how to properly inject gather-take into map:
sub MAIN ...
6
votes
1
answer
115
views
How can you use multiple modules in a Raku project, if the modules are defined in the project?
I'm playing around with writing modules in Raku, when it made sense for me to break a piece of functionality off into another .rakumod file. How can I link these files together when I compile?
I tried ...
7
votes
3
answers
280
views
How much does Raku's Promise construct share in common with JavaScript's Promises?
I'm learning asynchronous programming in JS and I couldn't help but noticed both JS and Raku has some construct for asynchronous programming with the same name, however I'm uncertain to what extent ...
7
votes
2
answers
155
views
How to use CStruct
I'm trying to return struct from shared library written in C. This is simple code, for testing of returning structure and simple int32, libstruct.c, compiled by gcc -shared -Wl,-soname,libstruct.so.1 -...
5
votes
2
answers
150
views
Shouldn't the same srand value produce the same random numbers?
When I repeatedly run this code,
srand 1;
my @x = (1..1000).pick: 100;
say sum @x;
I get different answers each time. If I'm resetting with srand why shouldn't it produce the same random numbers ...
5
votes
1
answer
133
views
How are dynamically scoped variables implemented in Rakudo/MoarVM?
That is, variables like $*scalar, @*array and %*hash.
I'm asking this question mainly because I want to have an idea of how much of a burden they are on the overall performance of the grammar/regex ...
6
votes
1
answer
82
views
Cannot locate SDL2.dll in Rakudo
Recently I've been trying to learn the Raku language, and I tried to make a simple Snake Game.
The code starts with this :
use SDL2::Raw;
use Cairo;
But when I compile using rakudo raku.raku, I get ...
0
votes
1
answer
106
views
Raku project suddenly starts to fail [closed]
I have a medium sized Raku project that all of a sudden started to throw the following error on startup:
===SORRY!=== Error while compiling /home/patrickb/repos/RakudoCIBot/service.raku
===SORRY!=== ...
10
votes
1
answer
103
views
Multi-dispatch to candidate with native parameters not working
I am trying to use multi in my Raku code that wraps a function in C.
Here I am calling lchoose function in shared libray Rmath.
This is my code which works:
use NativeCall;
constant RMATH = "./...
12
votes
1
answer
146
views
Understanding Cro request/response cycle and memory use
I'm a bit confused about how Cro handles client requests and, specifically, why some requests seem to cause Cro's memory usage to balloon.
A minimal example of this shows up in the literal "Hello ...
10
votes
1
answer
251
views
Assignment destructuring and operator precedence
The documentation says that the comma operator has higher precedence than the assignment = operator, and this is specifically different than in Perl, so that we are allowed to remove parentheses in ...
4
votes
1
answer
214
views
Is there a Raku method that allows a hash value to be sorted and split from its pair?
I am currently trying to use hashes in an array to find the keys and values of each specific item in the array. I am able to do this and both the keys and the values are separate when I haven't sorted ...
6
votes
2
answers
168
views
move function does not work in Raku in Windows
This is my folder structure:
C:\USERS\SUMAN\OPENMP_CMAKE
│ shlib.pl
│ shlib.raku
│
└───resources
└───libraries
the shlib.raku contains this line
move "shlib.pl", "resources/...
5
votes
1
answer
101
views
How to check if a program is present in the system with Raku?
I want to look if cmake is installed in my system with Raku.
cmake --version at my command line gives:
cmake version 3.23.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
One ...
4
votes
0
answers
63
views
Cannot use example about roles from official doc in Raku
Following this defenitions from docs.raku, I get the following error with rakudo 2022.03
platform-pro (pro) in ~ via ⬢ v12.4.0
❯ raku ...
6
votes
2
answers
163
views
srand in Raku, is it expected?
I am trying to run a code containing srand function:
srand(1);
my @x = (1..1000).roll(100);
my @y = (200..7000).roll(100);
say sum(@x);
say sum(@y);
say $*KERNEL
From the docs its pretty clear that ...
3
votes
0
answers
92
views
Getting error "Could not load oplib `nqp_dyncall_ops'" + traceback when executing raku one liner
I have a rakudo instance that will do nothing other than respond with "Could not load oplib 'nqp_dyncall_ops'".
Using the REPL:
perl6
Could not load oplib 'nqp_dyncall_ops
exit
Unable to ...
9
votes
1
answer
186
views
RAKUDO_RAKUAST=1 raku --target=ast is not yet available
It has been almost a year since I saw Jonathan Worthington presenting the new RakuAST in the YouTube video A Raku API to Raku programs the journey so far from TRC 2021. In the video, he showed that ...
7
votes
2
answers
121
views
Making exported functions in submodules accessible in global namespace in Raku
I created a minimal working module called new. The folder structure, link here is as follows:
new
│ .gitignore
│ Changes
│ dist.ini
│ LICENSE
│ META6.json
│ README.md
│
├───lib
│ │ new....
7
votes
3
answers
96
views
Precedence inside a function call
Using the defined-or operator ( // ) in a function call produces the result I'd expect:
say( 'nan'.Int // 42); # OUTPUT: «42»
However, using the lower-precedence orelse operator instead throws an ...
8
votes
1
answer
101
views
What's the difference between $?CLASS and ::?CLASS
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 ...
9
votes
2
answers
229
views
What's the point of Raku's 'mod' operator?
I previously incorrectly thought that the % operator returned the remainder and the mod operator returned the modulus (the remainder and modulus are the same when the operands are both positive or ...
11
votes
3
answers
161
views
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 ...
7
votes
2
answers
108
views
Dynamically created class with invocant constraint
Official docs says that class can be built dynamically like so:
constant A := Metamodel::ClassHOW.new_type( name => 'A' );
A.^add_method('x', my method x(A:D:) { say 42 });
A.^compose; ...
8
votes
1
answer
115
views
EXPORTHOW and DECLARE - what are they?
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 ...
6
votes
1
answer
80
views
"compose_attributes" is apparently called before attributes are composed
This is another attempt to do this thing, essentially create a frozen class:
my class MetamodelX::Frozen is Metamodel::ClassHOW {
method compose_attributes(Mu \type) {
for self....
4
votes
0
answers
76
views
Enforcing read-only attributes from the metaclass
Yes, still going with this. My impression is that there's this powerful facility in Raku, which is not really easy to use, and there's so little documentation for that. I'd like to kind of mitigate ...
5
votes
1
answer
73
views
Enforcing single instances from the metamodel
I know that it's way easier to ensure single instances from the class level, and that there's the excellent Staticish module from Jonathan Stowe that does the same by using roles, but I just want to ...
6
votes
1
answer
114
views
What counts as a newline for Raku *source* files?
I was somewhat surprised to observe that the following code
# comment
say 1;
# comment
say 2;
# comment say 3;
# comment say 4;
prints 1, 2, 3, and 4.
Here are the relevant characters after "# ...
7
votes
2
answers
194
views
Formatting in Raku
I have written a function that outputs a double, upto 25 decimal
places. I am trying to print it as a formatted output from Raku.
However, the output is incorrect and truncated.
See MWE:
my $var = 0....
11
votes
3
answers
164
views
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 ...
10
votes
1
answer
108
views
Why can't a sub access dynamic variables when used in a "return"ed map in raku?
It seems that a a sub cannot access dynamic variables when it is used inside a map and that map is "return"ed.
Consider this piece of code:
sub start {
my $*something = 'foobar';
...
5
votes
2
answers
158
views
Where does the $*REPO dynamic variable obtain its values, and how to change/alter them?
This question is complementary to figuring out why this error (which started as a zef error) occurs.
Apparently, in certain circumstances the repository chain accessible from $*REPO may vary. Namely, ...
10
votes
1
answer
174
views
Symbols that break the identifier rules, e.g. `sub ::("☺") { }`
With the current Rakudo compiler (v2021.10), symbols declared with the ::(…) form do not need to follow the rules for identifiers even when they declare the name of a routine.
This means that the ...
7
votes
1
answer
80
views
Using EXPORTHOW to make declarator that acts like "sub"
The excellent 2011 Advent of Raku post Meta-programming: what, why and how provides a few clear examples of using EXPORTHOW to create a declarator that acts like class. Here's the first:
my class ...
8
votes
6
answers
219
views
Calling a module does not work in Raku in Windows
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 ...
8
votes
1
answer
130
views
Summing list of lists in Raku
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
# ...
13
votes
1
answer
286
views
Parsing binary files in Raku
I would like to parse binary files in Raku using its regex / grammar engine, but I didn't found how to do it because the input is coerce to string.
Is there a way to avoid this string coercion and use ...
11
votes
2
answers
359
views
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 ...
7
votes
1
answer
125
views
Changing the target of a `whenever` block from the inside
The following code attempts to react to one Supply and then, based on the content of some message, change its mind and react to messages from a different Supply. It's an attempt to provide similar ...
8
votes
1
answer
108
views
Can I copy a function with its *current* state?
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; #...
12
votes
1
answer
171
views
Understanding the point of supply blocks (on-demand supplies)
I'm having trouble getting my head around the purpose of supply {…} blocks/the on-demand supplies that they create.
Live supplies (that is, the types that come from a Supplier and get new values ...
10
votes
1
answer
144
views
Checking if a react block is ready for business
When writing concurrent code, it's fairly common to want to spin off a separate (green or OS) thread and then ask the code in that thread to react to various thread-safe messages. Raku supports this ...
7
votes
3
answers
265
views
What are the rules for re-binding?
[NOTE: I asked this question based on an older version of Rakudo. As explained in the accepted answer, the confusing output was the result of Rakudo bugs, which have now been resolved. I've left the ...
10
votes
2
answers
274
views
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(&...
10
votes
1
answer
107
views
Destructuring/list assignment with the `has` declarator
[I ran into the issues that prompted this question and my previous question at the same time, but decided the two questions deserve to be separate.]
The docs describe using destructuring assignment ...
9
votes
1
answer
183
views
Destructuring assignment in object creation
As with my previous question, this is an area where I can't tell if I've encountered a bug or a hole in my understanding of Raku's semantics. Last time it turned out to be a bug, but doubt lightning ...
8
votes
1
answer
155
views
Confusing .fmt behavior with nested Lists
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 ...