2,075 questions
1
vote
2
answers
62
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 ...
4
votes
1
answer
61
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=...
6
votes
2
answers
183
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 ...
4
votes
2
answers
149
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
140
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....
4
votes
1
answer
111
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
133
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
158
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
136
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
131
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
80
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
384
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 ...
5
votes
1
answer
123
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
113
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
304
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 ...