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

How do I find the index of the maximum value in a list in Perl 6?

It's easy enough to find the maximum value in a list in Perl 6: > my @list = 1,4,9,7,3; > say @list.max; 9 But if I want to find the index of the maximum entry, there doesn't seem to be an elegant way to do this. > say (^@list).sort({ -@list[$_]…
mscha
  • 6,509
  • 3
  • 24
  • 40
12
votes
1 answer

How to make `-n=3` the same as `-n 3` in Perl 6?

Perl 6 has great builtin command-line parsing via MAIN. However, I faced a problem which seems to be trivial, but I cannot figure it out. A simple MAIN: sub MAIN(Int :n(:$num)) { say "You passed: " ~ $num; } Then I can call my script as: $…
cuonglm
  • 2,766
  • 1
  • 22
  • 33
12
votes
3 answers

What is a twigil in Perl6?

I'm reading this fantastic introduction to Perl6 and came across a rather interesting term: Note the ! twigil means “this is private to the class”. class ScoreKeeper { has %!player-points; } I know what sigils are in Perl5. But what's a…
Zaid
  • 36,680
  • 16
  • 86
  • 155
12
votes
3 answers

What is the release date for Rakudo Star (perl6)?

If a specific release date is not available (as I suspect it is not), can you provide resources for tracking how close it is to the desired feature set that allows release. I'm not necessarily asking for a percentage gauge, or X of Y features…
kbenson
  • 1,464
  • 9
  • 13
11
votes
1 answer

Strange behavior when changing $*SCHEDULER after execution of external program

Description There is an example: #!/bin/env raku run 'raku', '-e', 'say "ok"'; exit 0; my $*SCHEDULER = ThreadPoolScheduler.new(max_threads => 128); On linux output is: ok Unhandled exception in code scheduled on thread 4 No such method 'cue' for…
fingolfin
  • 591
  • 9
11
votes
1 answer

Too few positionals passed, why?

sub hanoi(Int:D $n, Str:D $start, Str:D $end, Str:D $extra, &move_disk:(Int:D, Str:D, Str:D --> Nil) --> Nil) { if $n == 1 { move_disk(1, $start, $end); # Step 1 } else { hanoi($n - 1,…
vonbrand
  • 11,412
  • 8
  • 32
  • 52
11
votes
5 answers

Why does `BUILD` not see attribute from parent class?

class A { has $.name; }; class B is A { submethod BUILD { $!name = 'foo' } }; This code looks natural but throws error. Attribute $!name not declared in class B Yes, it is not declared in class B, but we are in the partially constructed object…
Pawel Pabian bbkr
  • 1,139
  • 5
  • 14
11
votes
3 answers

How can I create a factory for classes? Getting "undeclared name" error

I have this code: class kg is Dimension { method new() { return self.bless( :type('mass'), :abbr('kg'), :multiplier(Multiplier.new( numerator => 1.0, …
StevieD
  • 6,925
  • 2
  • 25
  • 45
11
votes
1 answer

What Raku regex modifier makes a dot match a newline (like Perl's /s)?

How do I make the dot (.) metacharacter match a newline in a Raku regex? In Perl, I would use the dot matches newline modifier (/s)?
itil memek cantik
  • 1,167
  • 2
  • 11
11
votes
3 answers

Using NativeCall to call the C fn `erf` gets more precise output than `erf` in C

I have written a Raku script to call erf function in C standard library: use NativeCall; sub erf(num64) returns num64 is native { * }; say [0.5,1,2,3,4,-0.9].map: {erf($_.Num)}; The output of this script (0.5204998778130465 0.8427007929497149…
Suman Khanal
  • 3,079
  • 1
  • 17
  • 29
11
votes
3 answers

How to apply one signature test to multiple positionals

I wrote some code in https://github.com/p6steve/raku-Physics-Measure that looks for a Measure type in each maths operation and hands off the work to non-standard methods that adjust Unit and Error aspects alongside returning the new value: multi…
librasteve
  • 6,832
  • 8
  • 30
11
votes
2 answers

Getting the last element of a lazy Seq in Raku

I want to get the last element of a lazy but finite Seq in Raku, e.g.: my $s = lazy gather for ^10 { take $_ }; The following don't work: say $s[* - 1]; say $s.tail; These ones work but don't seem too idiomatic: say (for $s<> { $_ }).tail; say…
Nikola Benes
  • 2,372
  • 1
  • 20
  • 33
11
votes
2 answers

How to execute raku script from interpreter?

I open raku/rakudo/perl6 thus: con@V:~/Scripts/perl6$ perl6 To exit type 'exit' or '^D' > Is the above environment called the "interpreter"? I have been searching forever, and I cannot find what it's called. How can I execute a rakudo script like…
con
  • 5,767
  • 8
  • 33
  • 62
11
votes
2 answers

How to get a "help" functionality in REPL

When I use REPL, I sometimes need to look up how a function functions e.g. splice. I usually go to the documentation website. But I don't always have internet and it'd be good if I could write help("splice") or something (e.g. splice?) in the REPL…
user15750474