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
22
votes
2 answers

How many ways are there to describe the Fibonacci sequence in Perl 6?

I've been looking at the various ways of constructing lazy lists in Perl 6 and I would like to collect all of the concise ways of describing the Fibonacci sequence. I will start this off with the three from masak's journal: my @fibs := (0, 1, -> $a,…
Eric Strom
  • 39,821
  • 2
  • 80
  • 152
21
votes
2 answers

Method/Sub Binding In Raku

I'd like to find out if there is a way to bind a method and/or a sub to another method/sub name in Raku. I've seen how you can bind a variable to a method/sub, but that's not quite what I'm looking for. I know how to do it in Perl 5: sub sub1 { …
JustThisGuy
  • 1,109
  • 5
  • 10
20
votes
3 answers

Can Raku range operator on strings mimic Perl's behaviour?

In Perl, the expression "aa" .. "bb" creates a list with the strings: aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az ba bb In Raku, however, (at least with Rakudo v2021.08), the same expression creates: aa ab ba…
Nikola Benes
  • 2,372
  • 1
  • 20
  • 33
20
votes
2 answers

How can I completely flatten a list (of lists (of lists) ... )

I was wondering about how I could completely flatten lists and things that contain them. Among other things, I came up with this solution that slips things that have more than one element and puts them back, or takes things with one element after…
brian d foy
  • 129,424
  • 31
  • 207
  • 592
19
votes
2 answers

How can I split a string in every possible way?

Given the word abcd, how would I construct the following nested list? [ (abcd) (a bcd) (ab cd) (abc d) (a b cd) (a bc d) (ab c d) (a b c d) ] That is splitting the word in every way it can be, while keeping the letters in order. Nemokosch on…
Jim Bollinger
  • 1,671
  • 1
  • 13
19
votes
3 answers

Haskell-like pattern matching in Raku

Haskell and Rust (and maybe other languages of which I am not aware) have a feature which they call "pattern matching". Here is an example in Haskell: data Event = HoldKey Char | PressKey Char | Err String someFunc = let someEvent <-…
Dincio
  • 1,010
  • 1
  • 13
  • 25
19
votes
1 answer

Does Raku have a global interpreter lock (GIL)?

The Wikipedia article Global interpreter lock indicates that Raku has a global interpreter lock. This contradicts Curtis Poe's response to Are any companies planning to use Perl 6?. I suspect that the Wikipedia article is wrong - but maybe it is…
Ross Attrill
  • 2,594
  • 1
  • 22
  • 31
19
votes
2 answers

What's the difference between :D and :D:?

I was browsing the Perl 6 docs on the shift routine and saw this snippet: Defined as: multi sub shift(Array:D ) multi method shift(Array:D:) I know :D means the Array is defined and not Any or Nil, but what's :D:? It's very hard to search…
cat
  • 3,888
  • 5
  • 32
  • 61
19
votes
4 answers

Is there a working CPAN/CPAN6 like project for Perl 6?

I'm playing around with Rakudo Perl 6 lately and was searching for a project similar to CPAN. I found CPAN 6, but I think there is no Perl 6 code yet. So I'm looking for some alternative that does not necessarily aim to be a long term solution, but…
matthias krull
  • 4,389
  • 3
  • 34
  • 54
18
votes
5 answers

In Raku, how does one write the equivalent of Haskell's span function?

In Raku, how does one write the equivalent of Haskell's span function? In Haskell, given a predicate and a list, one can split the list into two parts: the longest prefix of elements satisfying the predicate the remainder of the list For example,…
user3134725
  • 1,003
  • 6
  • 12
18
votes
3 answers

What's the real difference between a token and a rule?

I was drawn to Raku due to its built-in grammars and figured I'd play around with it and write a simple email address parser, only problem: I couldn't get it to work. I tried countless iterations before landing on something that actually works, and…
Electric Coffee
  • 11,733
  • 9
  • 70
  • 131
18
votes
2 answers

perl6 grammar , not sure about some syntax in an example

I am still learning perl6, and I am reading the example on grammar from this page: http://examples.perl6.org/categories/parsers/SimpleStrings.html ; I have read the documentations on regex multiple times, but there are still some syntax that I don't…
lisprogtor
  • 5,677
  • 11
  • 17
18
votes
2 answers

How does one write custom accessor methods in Perl6?

How does one write custom accessor methods in Perl6? If I have this class: class Wizard { has Int $.mana is rw; } I can do this: my Wizard $gandalf .= new; $gandalf.mana = 150; Let's say I want to add a little check to a setter in my Perl6…
Adam Libuša
  • 685
  • 7
  • 24
17
votes
1 answer

How do I register different events in a supply in Raku?

Hopefully "events" isn't a misnomer in Rakuland. As far as I understand, Supplies are the Raku equivalent for "events" in other programming languages such as NodeJS. In NodeJS, you can register different events which can be targeted specifically…
uzluisf
  • 2,586
  • 1
  • 9
  • 27
17
votes
1 answer

Multi subroutine recursive in Raku

I'm learning raku, following the book Thinking in Raku There is an exercise that I need to define the ackermann function. I defined a positive Integer subset: subset Positive-Integer of Int where { $_ > 0} Then I goes through the recursive version…
anquegi
  • 11,125
  • 4
  • 51
  • 67