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

Understanding Raku's `&?BLOCK` compile-time variable

I really appreciate the Raku's &?BLOCK variable – it lets you recurse within an unnamed block, which can be extremely powerful. For example, here's a simple, inline, and anonymous factorial function: { when $_ ≤ 1 { 1 }; $_ × &?BLOCK($_ - 1)…
codesections
  • 8,900
  • 16
  • 50
12
votes
1 answer

How to provide a non-slurpy array or named array from the command line?

First of all: raku (perl6) is amazing. And so is Cro. It only took a week-end to fall in love. However now I stumble over something that must be extremely simple. If I use a slurpy parameter in a multiple dispatch MAIN this is recognized and works…
12
votes
5 answers

Determine if a variable in Raku is set

I intentionally avoid the term defined because a variable may very well have a defined value but the .defined method will return false (Failures, for instance). Is there any way to determine whether a variable has had a value set to it? my $foo; say…
user0721090601
  • 5,276
  • 24
  • 41
12
votes
2 answers

Alternative to Perl's <> in Raku?

Here learning my way around Raku (neé Perl 6), very nice all around. But I sorely miss the magic <> from Perl 5, where you can just: my $x = <>; print $x; while(<>) { print join(':', split); } (read next input line into $x, loop over the rest;…
vonbrand
  • 11,412
  • 8
  • 32
  • 52
12
votes
2 answers

Scalar value being affected after push, or not... (Raku)

I have difficulty understanding when and why the value held by a pushed Scalar container is affected after the push. I'll try to illustrate the issue that I ran into in a more complicated context in two stylized examples. *Example 1 * In the first…
ozzy
  • 785
  • 3
  • 12
12
votes
1 answer

How do you access private methods or attributes from outside the type they belong to?

In some rare cases where this would actually be acceptable, like in unit tests, you may want to get or set the value of a private attribute, or call a private method of a type where it shouldn't be possible. Is it really impossible? If not, how can…
Kaiepi
  • 3,230
  • 7
  • 27
12
votes
2 answers

What are the truthy and falsy values in Raku?

While it is always possible to use mixins or method overrides to modify the Bool coercions, by default what values are considered to be truthy and what values are considered to be falsy? Note: this question was asked previously, but unfortunately it…
user0721090601
  • 5,276
  • 24
  • 41
12
votes
5 answers

perl6 What is a quick way to de-select array or list elements?

To select multiple elements from an array in perl6, it is easy: just use a list of indices: > my @a = < a b c d e f g >; > @a[ 1,3,5 ] (b d f) But to de-select those elements, I had to use Set: > say @a[ (@a.keys.Set (-) (1,3,5)).keys.sort ] (a c e…
lisprogtor
  • 5,677
  • 11
  • 17
12
votes
2 answers

How do I match a hex array in perl6 grammar

I have a string like "39 3A 3B 9:;" and i want to extract "39, 3A, 3B" I have tried my $a = "39 3A 3B 9:;"; grammar Hex { token TOP { + .* } token hex_array { <[0..9 A..F]> " " } }; Hex.parse($a); But this doesn't seem to…
tejas
  • 1,795
  • 1
  • 16
  • 34
12
votes
2 answers

Raku: Sorting Hash by Values and using kv

I'm looking at the following Data (in JSON) { "FValidation_pipelineMTHXT_v4.5.1_refLibV2": "concordance2/f", "FValidation_pipelineLPJL": "concordance2/c", "FCompetenceRuns": "concordance2/b", "FWGS": "concordance2/a", …
con
  • 5,767
  • 8
  • 33
  • 62
12
votes
1 answer

Is there subscript syntax to extract a diagonal from a 2D Array?

I mostly can follow the syntax to 'drill down/slice' into an array with multiple dimensions (and flattening) on the docs page. A very cool feature. For example given: my @a=[[1,2,3], [4,5,6], [7,8,9]]; I can select column 2 of the…
drclaw
  • 2,463
  • 9
  • 23
12
votes
2 answers

perl6 text substitution on array

I'm trying to apply a text substitution to an entire array. However, when I try to alter the array, it shows that it only has 1 element, when it should have 26. An example below in Perl6 REPL: > my @a = 'a'..'z' [a b c d e f g h i j k l m n o p q r…
con
  • 5,767
  • 8
  • 33
  • 62
12
votes
1 answer

Substitute: replacement evaluation

Is the first and the second substitution equivalent if the replacement is passed in a variable? #!/usr/bin/env perl6 use v6; my $foo = 'switch'; my $t1 = my $t2 = my $t3 = my $t4 = 'this has a $foo in it'; my $replace = prompt( ':' ); #…
sid_com
  • 24,137
  • 26
  • 96
  • 187
12
votes
1 answer

Perl6 IO::Socket::Async truncates data

I'm rewriting my P5 socket server in P6 using IO::Socket::Async, but the data received got truncated 1 character at the end and that 1 character is received on the next connection. Someone from Perl6 Facebook group (Jonathan Worthington) pointed…
Zarul Zakuan
  • 510
  • 3
  • 13
12
votes
5 answers

print sth every second, and also sleep 10 seconds very 5 seconds using react ... whenever in Perl 6?

I want to print the current time every second, and also want to sleep 10 seconds very 5 seconds: react { whenever Supply.interval(1) { say DateTime.now.posix; } whenever Supply.interval(5) { sleep 10; say 'Sleep…
chenyf
  • 5,048
  • 1
  • 12
  • 35