2,083 questions
6
votes
2
answers
164
views
How to use the raku operator 'ff'or 'fff' in a 'for lines()' loop
Given the input file:
----------------
A
----------------
information for A
on these lines
----------------
B
----------------
Something about B
on these lines
etc
I want to produce:
A: information ...
2
votes
1
answer
116
views
Why is the deep cloned object still linked?
Following the documentation and this SO answer I wrote the following class with clone method, but the tests in the code do not give the expected result.
use v6.d;
use Test;
class Numeration {
...
3
votes
2
answers
150
views
How to create a CL utility with an option set?
Background:
In build.rakumod I have several multi sub MAIN( ... ), one of which is:
multi sub MAIN(
:$config = 'config', #= localised config file
Bool :install($)!, #= install a config ...
5
votes
1
answer
167
views
Unable to print color when color code is taken from array
I have color codes stored in an array. I cannot print color when I take a color code from the array, but I can print color if I use the code directly in a "say" or "print" ...
1
vote
0
answers
118
views
I have a problem using the command line and Raku
This screen transcript pretty much says it all:
ftype
PerlScript=C:\strawberry\perl\bin\perl.exe "%1" %*
RakuScript=C:\rakudo\bin\raku.exe "%1" %*
assoc
.pl=PerlScript
.raku=...
2
votes
2
answers
200
views
Raku regex to match two consecutive dots but not three
I'm looking for a Raku regex that matches two or more consecutive dots unless there are three dots.
These strings should match:
Yes.. Please go away.
I have the ball..
In this case....I vote yes.
...
4
votes
0
answers
129
views
rakudo-star-2025.06.1 install failed
I have Linux kernel 5.15.0-94-generic. I downloaded rakudo-star-2025.06.1.tar.gz. I gunzip and tar xf in a directory, and in this directory, I do "./bin/rstar install" as I did with previous ...
3
votes
1
answer
133
views
how to refer to a sub exported by a module when using require?
Background: There are a number of modules in the local lib eg Eg-1.rakumod Eg-2.rakumod Eg-3.rakumod, each Eg-\d is referenced in META6.json file, and each module has the code
sub SITE is export { ... ...
2
votes
1
answer
129
views
Destructuring assignment to non-scalar variables
While binding works as I expected, assignment doesn't:
my ($a, @b, $c) := (42, <a b c>, 42);
say [$a, @b, $c]; # OUTPUTS: [42 (a b c) 42]
my ($d, @e, $f) = (42, <a b c>, 42);
say [$d, @e, ...
2
votes
2
answers
217
views
How do I get a count of duplicate lines using Raku?
When using a CLI it is possible to pipe the contents of a fil through uniq.
Is there an analogy of the GNU uniq -c function in Raku ?
For example,
one two
one three
one two
four five
is transformed ...
5
votes
3
answers
176
views
What is an idiomatic way to convert a query to a hash
The response to an HTTP request is a string like
'one=iwejdoewde&two=ijijjiiij&three=&four=endinghere'
I want to put this query into a hash. My solution is
my $s = 'one=iwejdoewde&two=...
7
votes
2
answers
230
views
How to use gather/take with race
I can parallelize execution using Hyper and it works:
$ raku -e 'race for (^8).race(batch => 1, degree => 4) {sleep rand; .say}'
0
3
5
2
1
7
4
6
But how can I add gather/take behavior to such ...
5
votes
2
answers
167
views
How to make altering a deep field more idiomatic
I have a hash with several layers of sub-hashes, and I want to alter all the modified fields in the bottom layer.
The hash has the following structure
%sources{$lang}{$filename}{$attribute}
The code ...
6
votes
0
answers
167
views
Writing async routines: use `start` or `Promise.then`?
I'm looking for the right way to write asynchronous routines. Here's a hypothetical example of some asynchronous javascript function:
async function someFunction() {
const data = await Promise....
5
votes
1
answer
125
views
How to explicitly use the default value of a parameter?
Let's say we have the following subroutine:
sub test($arg = 'defaut value') { say $arg }
And we want to pass some argument that will cause the subroutine to use the default value, something like this:...
5
votes
1
answer
161
views
Using Recursive Regexes in Raku: how to limit recursion-levels?
Raku has an interesting and exciting recursive-regex notation: <~~>.
So in the REPL, we can do this:
[0] > 'hellohelloworldworld' ~~ m/ helloworld /;
「helloworld」
[1] > '...
3
votes
1
answer
166
views
Really slow compilation of a big grammar [closed]
Reproducing
Sorry, I couldn't come up with an MRE. My code is on glot.io. It isn't perfect, because it's autogenerated. Here are steps to reproduce:
Step 1
Compile the code: time raku --stagestats ...
4
votes
2
answers
166
views
Is it ok to use binding when declaring variables?
I keep asking questions about sets in Raku to several AIs.
Now I asked again a question about sets in Raku to Deepseek.
It gave me the following example
# Create a mutable SetHash
my %set := SetHash....
5
votes
3
answers
152
views
I need a Raku grammar to change itself based on a different match
I want to write a Raku grammar to check a monthly report about work contribution factors, written in Racket/Scribble.
The report is divided, at the highest level, into monthly sections, and beneath ...
6
votes
1
answer
92
views
Inheriting from Array: construction
There is an example:
class A is Array {
has $.member = 42;
}
my $a = A.new: 1..10;
say $a.member; # OUTPUT: «(Any)»
Why doesn't it work? I also tried submethods TWEAK and BUILD, they also can't ...
9
votes
1
answer
402
views
Is there a way to have a short and two long command line argument alternatives for a parameter?
I have guessed multiple syntax variations to achieve this in a single line in the MAIN function. I know I could achieve it in two separate lines, but am looking for the cleaner solution and only ...
6
votes
1
answer
131
views
Copy some hash elements to another hash
Is there a more idiomatic way to create a hash with a sub-set of keys from another hash.
Currently I have:
a-subroutine('param',
%(:$level,
:id(%prm<id>), :target(%prm<target>),
...
6
votes
2
answers
136
views
How do I install the Raku Cro web framework using a dockerfile
I am attempting to wrap a Raku based web app in a dockerfile. I am using the Cro web framework but I cannot seem to install the Cro successfully.
I tried the dockerfile below:
# Use the official ...
7
votes
4
answers
411
views
"The Best Regex Trick" in Raku
The Best Regex Trick is about writing regexes that match r1 but not r2. The example they give is a regex that matches Tarzan (and "Tarzan and Jane") but not "Tarzan". After going ...
6
votes
1
answer
124
views
Unexpected flattening of arrays when initalizing an array
I'm not totally sure if this is a bug, a quirk, or simply a bad practice, but this is what happens:
[0] > my @nope = [["a","b"]]; @nope.push: ["b","c"]
[a b [...
5
votes
1
answer
192
views
How can I make a functional chaining operator in Raku?
I a trying to translate this F# code to Raku for learning purposes:
type Meat = Chicken | Beef | Pork | Fish | Veggie
type Ingredient =
| Cheese | Rice | Beans | Salsa | Guacamole | SourCream | ...
6
votes
1
answer
138
views
Possible Bug with run as Last Statement in try Block
I don't know if this is a bug, or I just don't understand what's happening. If I have a run statement as the last statement in a try block, any error in the run statement is not caught. If it is not ...
10
votes
1
answer
201
views
Why DateTime.now and Date.today.DateTime have different timezone?
[23] > my $now = DateTime.now
2024-09-29T14:59:10.178051+08:00
[24] > my $eight-hours-later = Date.today.DateTime.later(:8hours)
2024-09-29T08:00:00Z
[25] > $now - $eight-hours-later
-3649....
7
votes
1
answer
174
views
When `whenever` block in `react` section starts processing events?
Let's say I have simple socket listening in one thread and I want to hold another thread until port is opened and socket is actually listening. Which one is correct:
Using do? Documentation of do ...
4
votes
1
answer
105
views
Defining bareword operators in Raku
I have some questions regarding defining bareword operators in Raku. As it stands in the language, there are a variety of bareword operators, such as div, mod, gcd, & lcm. As I'm curious about the ...
6
votes
2
answers
221
views
How should Regexes be passed to MAIN in Raku?
Is there an idiomatic way to pass a Regex from the command line to a Raku program. The following code accomplishes what I'm trying to do but it has a few issues (see below).
#!/bin/raku
use MONKEY-...
6
votes
1
answer
151
views
How can I use Raku Grammars with the comb function?
I would like to use Raku's comb function with a regex from a Grammar instead of a standalone regex. For example, in the following code, which parses journalctl logs from stdin, I would like to replace ...
6
votes
2
answers
140
views
How to override default content type in Cro::HTTP::Client?
I'm creating an object for making HTTP requests like this:
$!ua = Cro::HTTP::Client.new(
base-uri => 'https://what.ever/api/',
content-type => 'application/...
6
votes
1
answer
124
views
How to do a multiple dispatch (or an alternative) for a single pair?
I really like the syntax of a pair :3melee which means melee => 3. I'd like to do the following:
my Creature $creature .= new(:fire-resist);
$creature.damage: :3melee;
$creature.damage: :3fire;
so ...
4
votes
1
answer
143
views
converting list of Str into list of Enums
I have an enum definition in a module AAA:
enum RDProcDebug <None All AstBlock BlockType Scoping Templates MarkUp>;
class Debug {
method foo(RDProcDebug @ds) {
for @ds { say .key ~ ' =>...
4
votes
2
answers
124
views
How to forward declare a role to be used for an enum?
Running this piece of code
use v6.d;
role DrawSurface { ... };
enum Surface does DrawSurface <Fire>;
role DrawSurface {
method draw () {
given self {
when Surface::...
4
votes
1
answer
125
views
Raku Actions Predicated on Parse Success?
Is there a way to configure Raku actions to only execute after a parse has completed successfully? For example, the program below outputs "Jane is telling us her age....", even with ...
5
votes
1
answer
164
views
Partial matching in a simple Raku program
I've created a simple program based on the Raku parsefile example provided here. The contents of my Raku file are:
grammar Names {
token TOP { [<name><.ws>]+ }
token name { <:alpha&...
4
votes
1
answer
108
views
looping through classes using require
I have a number of plugin classes each of which have a method 'enable'.
The following code works
unit class Top;
has $!rdp;
use Plugin::A;
use Plugin::B;
use Plugin::C;
submethod TWEAK {
my $rdp := ...
5
votes
1
answer
167
views
Raku: Using hyper or race with junctions
I have about 75000 files and I need to search each file for a set of key phrases stored in an array. I have Intel i9 capable of running 20 threads. I am trying to speed up the whole process by ...
5
votes
2
answers
195
views
Don't install a module if the operating system is Windows
Is it possible to write a META6.json file that
prints a message that the operating system is not supported
and does not try to install the module
if the operating system is Windows?
3
votes
1
answer
118
views
How to set a named parameter to an exported sub when importing a module?
unit module My::Show;
sub show (:$indent = False) is export {
if $indent {
say " Showing with indentation.";
} else {
say "Showing without indentation.";...
13
votes
1
answer
621
views
What does the $¢ variable do in Raku?
The documentation says that there are only 3 special lexical variables ($_, $/, $!).
However, inspecting the MY:: pseudostash, it seems that a variable named $¢ also exists, and is undocumented (or at ...
3
votes
1
answer
156
views
How to get a seq of enum members filtering out some members
I have an enum list with actions and the members None and All. How do I create a sequence of enums that filters out None and All?
Test program in file filter-enum.raku:
#!/usr/bin/env raku
use v6.d;
...
6
votes
1
answer
93
views
Can a Range evaluate to False in Bool context in Raku?
While making use of a Range to solve a problem I noticed that a Range with 0 elems would be True as a Bool. In what scenarios could a Range be False?
[0] > (^0).so
True
[1] > (1..0).so
True
4
votes
2
answers
122
views
Raku module fails to work with Google Sheets .clear API function
Apologies for the long question. I am working on the raku Net::Google::Sheets module.
Currently it does a good job of successfully using OAuth2::Client::Google and getting and putting a 2D Array from/...
8
votes
1
answer
165
views
Breaking brace after the start keyword
This is the simple program, it prints a terminal size when you resize it:
#!/bin/env raku
use NCurses;
initscr;
loop {
given getch() {
when 27 { last } # exit when pressing esc
...
6
votes
1
answer
111
views
How can I dynamically export classes in raku?
I am updating a raku module (Physics::Measure)
My old code looks like this:
unit module Physics::Measure ...
class Length is Measure is export {}
class Mass is Measure is ...
8
votes
0
answers
125
views
cannot use `OUTER` as label name for loop control in Raku
If I use OUTA as a label name it works, but OUTER doesn't:
OUTA: say OUTA.^name; # Label
OUTER: say OUTER.^name; # OUTER
Thus:
OUTA: loop { last OUTA } # works
OUTER: loop { last OUTER } # fails (...
8
votes
1
answer
162
views
Is it possible to append subroutines to a Raku module at runtime?
I would like to be able to add a sub to a module Foo at runtime.
In Perl, I would do something like:
*{'My::Module::foo'} = \sub { 'FOO!' };
I know Raku doesn't have TypeGlobbing like Perl. Ideally ...