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
14
votes
3 answers

Is there a sensible reason why the Perl 6 array constructor flattens its argument?

Given a single argument, the Array constructor flattens it. This causes problems: my %hash = (a => 1; b => 2); my @array = [ %hash ]; # result: [a => 1 b => 2], expected [{ a => 1, b => 2 }] The List constructor doesn't have this quirk (the…
piojo
  • 6,351
  • 1
  • 26
  • 36
14
votes
1 answer

Why is Perl 6's right associativity not right?

Clickbaity title but it's too meaty to pass up. I have this operator which I want to be right associative: sub infix:<↑> ( Int:D \n, Int:D \m --> Int:D ) is assoc is equiv(&infix:<**>) { n ** m } put "2**2**2**2 = ", …
brian d foy
  • 129,424
  • 31
  • 207
  • 592
14
votes
2 answers

Is that a Raku Hash or Block?

This is a bit of unexpected behavior that's likely to bite beginners. First, is this intended? Second, what other things does Raku use to guess which object to create? Does it start off thinking it's Block or Hash and change later, or does it decide…
brian d foy
  • 129,424
  • 31
  • 207
  • 592
14
votes
2 answers

How do I parse and validate command line arguments in Raku (formerly known as Perl 6)?

In Perl 5, I can use Getopt::Long to parse commandline arguments with some validation (see below from http://perldoc.perl.org/Getopt/Long.html). use Getopt::Long; my $data = "file.dat"; my $length = 24; my $verbose; GetOptions ("length=i" =>…
Christopher Bottoms
  • 11,218
  • 8
  • 50
  • 99
14
votes
1 answer

I can create filehandles to strings in Perl 5, how do I do it in Perl 6?

In Perl 5, I can create a filehandle to a string and read or write from the string as if it were a file. This is great for working with tests or templates. For example: use v5.10; use strict; use warnings; my $text = "A\nB\nC\n"; open(my $fh, '<',…
Christopher Bottoms
  • 11,218
  • 8
  • 50
  • 99
14
votes
2 answers

How can I compile perl6 file to exe

I am playing with perl6 version which built on MoarVM on windows. I created some perl6 file and want to compile it to exe. I tried the following: perl6 --target=MAST r.pl>r Now I want to compile the r to executable I found this link which talk…
smith
  • 3,232
  • 26
  • 55
14
votes
4 answers

How can I get started with Perl 6?

Could someone provide a link of material where to start with Perl 6? Also could someone point to real application already developed with Perl 6?
dan
  • 885
  • 2
  • 9
  • 18
13
votes
3 answers

Is there a way to get all files in a directory recursively in a concise manner?

I mean usable in one-liners. For example this: raku -e 'dir(".")==>say()' prints all files and directories in the current directory. How do I update it so it works recursively (without libraries and/or user-defined routines)? Or is it not…
menfon
  • 1,587
  • 1
  • 11
  • 28
13
votes
2 answers

Asynchronous reading of an stdout

I've wrote this simple script, it generates one output line per second (generator.sh): for i in {0..5}; do echo $i; sleep 1; done The raku program will launch this script and will print the lines as soon as they appear: my $proc =…
fingolfin
  • 591
  • 9
13
votes
2 answers

When does it make sense to use a sigil-less variable in Raku?

Raku sigils denote the nature of the underlying variable (e.g., $scalar, @positional, %associative, &code). It's possible to declare a variable as sigil-less with a backslash (e.g., \some-variable) and then later refer to it without a sigil (i.e.,…
user2145475
  • 657
  • 3
  • 11
13
votes
3 answers

How to divide every element in array by a certain number?

I have an array: my @e = <60.922 20.946 8.721 7.292 4.306 2.821 2.765 2.752 2.741 2.725> I would like to divide every element in the array by the minimum, however @e /= @e.min produced a single element, which…
con
  • 5,767
  • 8
  • 33
  • 62
13
votes
1 answer

Is there a way to automatically use FatRats in Raku?

One of the neat things of Raku is that it automatically uses rational numbers instead of floating point numbers, when appropriate (e.g. when dividing two integers). Unfortunately, once the denominator gets too large, floating point numbers are used…
mscha
  • 6,509
  • 3
  • 24
  • 40
13
votes
3 answers

`%_` and detecting unwanted named arguments to a method

As I understand, a named argument to a method goes to %_ if not found in the signature (not sure why!). To detect this, I do die "Extra args passed" if %_; for the methods I remember to do and that are worth doing. Is there a way to automate this…
user18174721
13
votes
2 answers

Can I write multiple raku Type smart matches on one line

I know that this will not work, since I tried it: if $r ~~ BearingTrue || CompassAdj || CourseAdj { nextsame }; But - is there a neat, concise and legible way to do multiple Type smart matches on one line rather than have to expand to a given/when…
librasteve
  • 6,832
  • 8
  • 30
13
votes
3 answers

Raku list addition operator `Z+` 'fails' unless one of the lists is forced

I'm struggling to understand why the zip-add Z+ operator does not work on some cases. I have some 2-element lists that I'd like to sum. These work as expected whether I use lists or arrays: say (1, 2) Z+ (3, 4) # (4, 6) say [1, 2] Z+ (3, 4) # (4,…
Julio
  • 5,208
  • 1
  • 13
  • 42