Skip to main content
Filter by
Sorted by
Tagged with
6 votes
2 answers
81 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 ...
Seamus Brady's user avatar
7 votes
4 answers
227 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 ...
Hovercouch's user avatar
  • 2,314
6 votes
1 answer
104 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 [...
jjmerelo's user avatar
  • 23.4k
5 votes
1 answer
166 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 | ...
librasteve's user avatar
  • 7,501
6 votes
1 answer
128 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 ...
JustThisGuy's user avatar
  • 1,189
10 votes
1 answer
174 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....
ohmycloudy's user avatar
7 votes
1 answer
153 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 ...
Pawel Pabian bbkr's user avatar
4 votes
1 answer
94 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 ...
Atlas Sullivan's user avatar
6 votes
2 answers
204 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-...
mikeLundquist's user avatar
6 votes
1 answer
138 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 ...
mikeLundquist's user avatar
6 votes
2 answers
111 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/...
VZ.'s user avatar
  • 22.6k
6 votes
1 answer
104 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 ...
Dmitry Matveyev's user avatar
4 votes
1 answer
117 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 ~ ' =>...
Richard Hainsworth's user avatar
4 votes
2 answers
108 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::...
Dmitry Matveyev's user avatar
4 votes
1 answer
118 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 ...
user2023370's user avatar
5 votes
1 answer
152 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&...
user2023370's user avatar
3 votes
1 answer
76 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 := ...
Richard Hainsworth's user avatar
5 votes
1 answer
153 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 ...
lisprogtor's user avatar
  • 5,749
5 votes
2 answers
180 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?
sid_com's user avatar
  • 25k
3 votes
1 answer
96 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.";...
Jim Bollinger's user avatar
13 votes
1 answer
595 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 ...
biancospino's user avatar
2 votes
1 answer
129 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; ...
Richard Hainsworth's user avatar
6 votes
1 answer
89 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
Daniel Mita's user avatar
4 votes
2 answers
116 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/...
librasteve's user avatar
  • 7,501
8 votes
1 answer
151 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 ...
fingolfin's user avatar
  • 672
6 votes
1 answer
100 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 ...
librasteve's user avatar
  • 7,501
8 votes
0 answers
117 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 (...
AlvaPan's user avatar
  • 619
8 votes
1 answer
144 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 ...
Rawley Fowler's user avatar
4 votes
3 answers
190 views

Why doesn't a Sequence get consumed when I assign it to an @var?

According to the class Seq docs: A Seq is born in a state where iterating it will consume the values. ... ... A Seq can also be constructed with the sequence operator ... or one of its variants. ...
7stud's user avatar
  • 48.6k
3 votes
3 answers
147 views

TR/// : How do you apply TR to a string?

With tr///, I can do this: my $str = 'xABCz'; $str ~~ tr:c/ABC//; say "-->{$str}<--"; --output:-- -->ABC<-- But with TR///, which creates a new string, there doesn't seem to ...
7stud's user avatar
  • 48.6k
2 votes
3 answers
244 views

Regex word boundary: <|wb> v. <?wb>

Edit: @ikegami was the first person to respond and pointed out my typo. The raku Regex docs say: To match any word boundary, use <|w> or <?wb>. This is similar to \b in other languages. ...
7stud's user avatar
  • 48.6k
6 votes
1 answer
200 views

Raku exceptions: why are errors thrown sometime after the code that caused the errors?

This seems crazy to me: use v6.d; say "Before division by zero!"; my $result = divide(3, 0); say "After division by zero!"; sub divide($a, $b) { my $result; $result = $a /...
7stud's user avatar
  • 48.6k
6 votes
2 answers
140 views

subset name of Any where Str|True: why does the name type match every type?

I expected the refinement of the Any type to Str|True would make the name type match any Str or True, but this is what I see: subset name of Any where Str|True; sub go(name :$x) { say $x; } go(x =...
7stud's user avatar
  • 48.6k
7 votes
3 answers
187 views

Mapping a List with a Hash argument

In the docs for class List, it says: routine map multi method map(Hash:D \hash) multi method map(Iterable:D \iterable) multi method map(|c) multi method map(\SELF: &block;; :$label, :$item) ...
7stud's user avatar
  • 48.6k
5 votes
1 answer
122 views

MAIN() function: how does multi-dispatch work?

Example 1: #!/usr/bin/env raku use v6.d; sub MAIN(Int $int) { say 'parameter $int: ', $int.^name; } --output:-- $ raku b.raku 10 parameter $int: IntStr Example 2: #!/usr/bin/env raku use v6....
7stud's user avatar
  • 48.6k
8 votes
1 answer
142 views

How to make a Raku test optional if a module is not installed

I am adding a feature to a package that optionally uses DBIish. I would like to write a few unit tests to ensure that the functionality is working. However, DBIish should be an optional dependency, ...
Rawley Fowler's user avatar
-2 votes
1 answer
188 views

Which 'Perl Traps' have not been fixed in Raku? [closed]

Looking at Perl, I was very pleased to find a link to a section called "Perl Traps" in the perldocs. It represents a refreshing sense of honesty in an increasingly tech-hyped world. The &...
jubilatious1's user avatar
  • 2,289
5 votes
3 answers
206 views

Does Raku has a data type for encoding side effects as pure values?

I am doing some exercise from the book Grokking Functional Programming, the origin code examples are written in Scala, and I want to rewrite it with Raku. In Scala's cats effect library, there is a ...
ohmycloudy's user avatar
8 votes
1 answer
161 views

How do I get a &-conjoined regular expression to be considered as long a match as its constituents?

You can specify that a regular expression should only match if all its constituents match by using a conjunction, && or &: [4] > 'ready' ~~ / r..dy & .ea.. / 「ready」 [5] > '...
darch's user avatar
  • 4,311
13 votes
2 answers
438 views

Is it possible to use the index of an array in a map block?

I would like to use the index of the array in a map routine. For example, this Raku code: raku -e 'my @a = "First", "Second", "Third", "First"; say @a.map({ &...
Mimosinnet's user avatar
9 votes
1 answer
165 views

How, and how best, to select a method/sub based on a boolean?

I have a method in a class to return a hash, with the aim that children classes will over-ride the method. But for testing purposes, I want a different hash. When the class is instantiated, I would ...
Richard Hainsworth's user avatar
5 votes
2 answers
149 views

How to extract data from RakuAST 's

How best is it to extract a hash from the config portion of a RakuAST::Doc::Block ? Here is the program: use v6.d; use experimental :rakuast; my $ast = Q:to/CONF/.AST; =for rakudoc :category("...
Richard Hainsworth's user avatar
7 votes
1 answer
147 views

Can't use sequence operator `...` on a separate line in Raku

The following code works: my @fibo = 1, 1, -> $a, $b { $a + $b } ... *; say @fibo[^10]; output: (1 1 2 3 5 8 13 21 34 55) But if you split this over multiple lines like this: my @fibo = 1, ...
mscha's user avatar
  • 6,822
4 votes
1 answer
134 views

Confused about 'capturing'-behavior of ( ... ) e.g. "immutable lists" vs. [ ... ] e.g. "arrays"

I'm somewhat confused about the behavior of the following Raku program, my @list; my $v = 4; @list.push: [ 1, $v ]; @list.push: ( 2, $v ); $v *= 2; @list.push: [ 3, $v ]; @list.push: ( 4, $v ); $...
chromis's user avatar
  • 183
8 votes
2 answers
235 views

How do I find all possible values of an enum in Raku?

enum Direction <north east south west>; for north, east, south, west -> $dir { say $dir; ... } I don't want to repeat the list of Direction values here. How can I programmatically ...
mscha's user avatar
  • 6,822
5 votes
1 answer
113 views

List seems to be reused but bare value works fine

This: my %dict; my $counter = 0; for ^5 -> $digit { %dict{$digit} = ($counter,); $counter += 1; } say %dict; gives me this: {0 => (5), 1 => (5), 2 => (5), 3 => (5), 4 =&...
marwy's user avatar
  • 329
5 votes
1 answer
91 views

Raku bug or feature: empty range is True

% raku Welcome to Rakudo™ v2023.08. Implementing the Raku® Programming Language v6.d. Built on MoarVM version 2023.08. To exit type 'exit' or '^D' [0] > say so 1..0; True It would be useful if an ...
mscha's user avatar
  • 6,822
2 votes
2 answers
173 views

Is there an elegant way in Raku to see if two ranges overlap?

Is there an elegant way to see if two ranges have any overlap? For instance, if my $r = 1..10; my $r1 = 2..5; my $r2 = 7..15; then $r1 ~~ $r is True. But $r ~~ $r1, $r2 ~~ $r, $r ~~ $r2 are all ...
mscha's user avatar
  • 6,822
5 votes
1 answer
146 views

Is it possible to lift a made value to Grammar TOP?

I have this raku Grammar: #!/usr/bin/env raku use v6.d; use Grammar::Tracer; grammar Grammar { token TOP { <city> \v <state-zip> \v? } token city { ...
librasteve's user avatar
  • 7,501
10 votes
1 answer
317 views

How to get the `< ... >` syntax on an object?

In Raku: when I create an object with a CALL-ME method, I would like to use the < ... > syntax for the signature instead of ( '...' ) when ... is a Str. In the documentation, there is an example ...
Richard Hainsworth's user avatar

1
2 3 4 5
42