Questions tagged [raku]

For questions relating to the Raku programming language (formerly known as Perl 6).

Raku

Raku is an expressive and feature-rich programming language designed by Larry Wall and developed by the community.

Features include:

  • Object-oriented programming
  • Functional programming primitives
  • Parallelism
  • Concurrency
  • Asynchrony
  • Definable grammars for pattern matching and generalized string processing
  • Optional and gradual typing
  • Extensive Unicode support from code points to grapheme clusters
  • Multiple dispatch
  • Introspection
  • Rational numbers

is a Raku implementation that targets multiple back ends.

The MoarVM back end is recommended for normal use, but back ends for the Java Virtual Machine and JavaScript are also under active development.

The Rakudo implementation shipped a first official release named “коледа” on December 25, 2015. Most of the specification is frozen, and optimizations are ongoing.

Official links

1993 questions
15
votes
2 answers

What does the dot before a postfix or postcircumfix in Perl 6 mean?

In the Perl doc, there is a section about .postfix/.postcircumfix, it says that In most cases, a dot may be placed before a postfix or postcircumfix: my @a; @a[1, 2, 3]; @a.[1, 2, 3]; # Same Technically, not a real operator; it's syntax…
chenyf
  • 5,048
  • 1
  • 12
  • 35
15
votes
3 answers

How to determine if an element exists in a Perl 6 array

I thought there would have been a simple answer for this somewhere on the internet but it seems like I'm having trouble finding a solution. I'm first of all wondering if there's a simple method or function for this: e.g. ~~ or array.contains() from…
Phyreprooph
  • 517
  • 2
  • 13
15
votes
4 answers

How do you add a method to an existing class in Perl 6?

The Int class has a method is_prime, so I figured, just for giggles, I'd like to add some other methods to Int for some of my hobby projects that do number theory stuff. I thought I could do something like this: class Int { method is-even (Int:D…
brian d foy
  • 129,424
  • 31
  • 207
  • 592
15
votes
2 answers

How can error reporting in grammars be improved?

Is there a way to get Perl 6 to generate an error message if a grammar does not match? Or at least return the position of the last data it processed? It is quite hard to fix syntax errors if all I get from the parser is 'no match'.
green lantern
  • 1,086
  • 7
  • 10
15
votes
2 answers

How to include file in Raku

I have two Raku files: hello.p6: sub hello { say 'hello'; } and main.p6: require 'hello.p6'; hello(); But don't work. How to can include the first file in the main script?
Juan Manuel
  • 311
  • 1
  • 11
14
votes
1 answer

How to convert Str to enum?

enum Colors say red; # OUTPUT: red my $foo = "red"; my Colors $color = $foo.(...) What code do I put in the Stub to convert the Str "red" to the Color red?
Jim Bollinger
  • 1,671
  • 1
  • 13
14
votes
1 answer

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 objects of type Buf or Blob ? I was thinking…
WhiteMist
  • 885
  • 4
  • 13
14
votes
4 answers

Documentation for the object Signature: " ... different name for a named argument than the variable name"

An example on the 'class Signature' page appears as: sub named(:official($private)) { "Official business!" if $private }; named :official; <----- Note: That's where to example ends ... there is no output described or shown. So I typed in the code…
Keith Hardy
  • 171
  • 4
14
votes
1 answer

What persistent data structures does Raku/Rakudo include?

Raku provides many types that are immutable and thus cannot be modified after they are created. Until I started looking into this area recently, my understanding was that these Types were not persistent data structures – that is, unlike the core…
codesections
  • 8,900
  • 16
  • 50
14
votes
3 answers

What's the protocol for calling Raku code from C code?

2023 update The last person to edit this Q deleted the critically important "LATEST LATEST UPDATE" part that @zentrunix had added near the top. I'm reinstating it. LATEST LATEST UPDATE Please see my answer below. Thanks to everyone who took the time…
zentrunix
  • 2,098
  • 12
  • 20
14
votes
1 answer

Raku regex: Inconsistent longest token matching

Raku's regexes are expected to match longest token. And in fact, this behaviour is seen in this code: raku -e "'AA' ~~ m/A {say 1}|AA {say 2}/" # 2 However, when the text is in a variable, it does not seem to work in the same way: raku -e "my $a =…
Julio
  • 5,208
  • 1
  • 13
  • 42
14
votes
1 answer

What are the specifics about the continuations upon which Raku(do) relies?

The topic of delimited continuations was barely discussed among programming language enthusiasts in the 1990s. It has recently been re-emerging as a major thing in programming language discussions. Aiui continuations aren't directly exposed in Raku,…
raiph
  • 31,607
  • 3
  • 62
  • 111
14
votes
3 answers

How can I define a Raku grammar to parse TSV text?

I have some TSV data ID Name Email 1 test test@email.com 321 stan stan@nowhere.net I would like to parse this into a list of hashes @entities[0] eq "test"; @entities[1] eq "stan@nowhere.net"; I'm having trouble…
littlebenlittle
  • 833
  • 2
  • 9
  • 18
14
votes
1 answer

Difficulty when constructing a nested data structure

While trying to create a JSON message for an API, I found myself struggling to do something that I thought would be simple. I needed to create a message like the following: { "list": [ { "foo": 1, "bar": 2 } ] } However, my first attempt did not…
jja
  • 2,058
  • 14
  • 27
14
votes
1 answer

Why does Raku perform so bad with multidimensional arrays?

I am curious why Raku performs so bad manipulating multidimensional arrays. I have made a quick test initializing a 2 dimension matrix in Python, C# and Raku and the elapsed time is surprisingly high for the later. For Raku my @grid[4000;4000] = [[0…
Javi
  • 305
  • 2
  • 7