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
16
votes
1 answer

Does Perl 6 have an equivalent to Python's dir()?

I'm trying to become comfortable in Perl 6. One of the things I found handy in Python when I was at a REPL prompt was that I could do a dir(object) and find out the attributes of an object, which in Python includes the object's methods. This often…
Steve Piner
  • 175
  • 5
15
votes
2 answers

How can I use Perl 5 modules from Perl 6?

Is the a way to use Perl 5 modules from CPAN from Rakudo Perl 6? For example, how can I use the venerable Perl 5 module, CGI, which hasn't been ported yet, in Perl 6. Update: And what this funky code from some early Perl 6 module: use…
GeneQ
  • 7,485
  • 6
  • 37
  • 53
15
votes
1 answer

Lookaround regex and character consumption

Based on the documentation for Raku's lookaround assertions, I read the regex / / as saying "starting from the left, match but do not not consume one character that is a, b, or c and, once you have found a match, match and consume…
codesections
  • 8,900
  • 16
  • 50
15
votes
5 answers

Is there a programmatic way to elaborate the 'half-winds' in raku?

I have this working: my %pnt = %( cardinal => , ordinal => , half-winds => , ); and I thought it may be possible to create…
librasteve
  • 6,832
  • 8
  • 30
15
votes
1 answer

How do I declare a dependency that can be fulfilled by one of many differently named packages?

In a Raku distribution how do I depend on either Foo::Bar or Foo::Baz without requiring both?
ugexe
  • 5,297
  • 1
  • 28
  • 49
15
votes
2 answers

How to generate a lazy division?

I want to generate the sequence of 1, 1/2, 1/3, 1/4 ... * using functional programming approach in raku, in my head it's should be look like: (1,{1/$_} ...*)[0..5] but the the output is: 1,1,1,1,1 The idea is simple, but seems enough powerful for…
metagib
  • 223
  • 1
  • 5
15
votes
1 answer

Cannot assign an if statement to a variable

The problem here is that I do not understand well the difference between statements and blocks in control flow. Looking the ternary operator I can use it to assign a variable. But this is an operator, so it is like applying a function--isn't it? >…
anquegi
  • 11,125
  • 4
  • 51
  • 67
15
votes
3 answers

Convert a word's characters into its ascii code list concisely in Raku

I'm trying to convert the word wall into its ascii code list (119, 97, 108, 108) like this: my @ascii="abcdefghijklmnopqrstuvwxyz"; my @tmp; map { push @tmp, $_.ord if $_.ord == @ascii.comb.any.ord }, "wall".comb; say @tmp; Is there a way to use…
Lars Malmsteen
  • 738
  • 4
  • 23
15
votes
3 answers

How to keep Nil from reverting container to its default value?

I'm implementing a simple linked list and to denote the fact that there is no next node, I'm using the value Nil. The thing is that when assigned to a container, Nil will attempt to revert the container to its default value which means I need to use…
uzluisf
  • 2,586
  • 1
  • 9
  • 27
15
votes
2 answers

What's the benefit of assigning non-scalars to scalars?

I sometimes see code that (to me) uses the wrong sigil in front of the variable my $arr = [1, 2, 3, 4, 5]; # an array my $lst = (1, 2, 3, 4, 5); # a list my $hash = {a => '1', b => '2'}; # a hash my $func = -> $foo { say $foo }; # a…
Electric Coffee
  • 11,733
  • 9
  • 70
  • 131
15
votes
1 answer

Cannot overload logical operators (or, and) for my class

I was trying to overload the logical or operator for a custom class, but it doesn't seem to work. This is what I do: class A { has $.a } multi sub infix: (A $a, A $b) { "works!({$a.a}, {$b.a})" } say A.new(:1a) or A.new(:2a); I'm expecting…
gmoshkin
  • 1,106
  • 8
  • 22
15
votes
3 answers

Variable number of arguments to function/subroutine

I want to be able to run a function with a variable number of parameters in Raku, but after reading through https://docs.raku.org/language/functions#Arguments I don't see how it can be done. I want to do something like this: some-test($v1,…
con
  • 5,767
  • 8
  • 33
  • 62
15
votes
1 answer

How to use a constants value as a hash key

Is there a simple way to use the value of a defined constant as a hash / pair key in Perl6? For instance : constant KEY = "a string"; my %h = ( KEY => "a value" ); This will creatre a key of "KEY" not "a string". I can do : my %h = ( "{KEY}" => "a…
Scimon Proctor
  • 4,558
  • 23
  • 22
15
votes
1 answer

Perl6 : What is the best way for dealing with very big files?

Last week I decided to give a try to Perl6 and started to reimplement one of my program. I have to say, Perl6 is so the easy for object programming, an aspect very painfull to me in Perl5. My program have to read and store big files, such as whole…
Sebus
  • 430
  • 2
  • 10
15
votes
2 answers

[] reduce with anonymous function in Perl 6

We can use reduce with a sub with two arguments, putting it in double brackets: > sub mysum { $^a + $^b } > [[&mysum]] 1,3,5 9 But what if we want to use an anonymous function instead? Both following variants produce a compile error: > [[&{ $^a +…
Eugene Barsky
  • 5,780
  • 3
  • 17
  • 40