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

How do I write a perl6 macro to enquote text?

I'm looking to create a macro in P6 which converts its argument to a string. Here's my macro: macro tfilter($expr) { quasi { my $str = Q ({{{$expr}}}); filter-sub $str; }; } And here is how I call…
blippy
  • 1,490
  • 1
  • 13
  • 22
6
votes
2 answers

Passing an array of structures to a Perl 6 NativeCall function

I'm trying to use NativeCall to interact with some C functions. I have a simple C struct, and a function that wants an array of them. struct foo { int x; char *s; }; struct foo foo_array[3]; foo_array[0].x = 12; foo_array[0].s =…
Curt Tilmes
  • 3,035
  • 1
  • 12
  • 24
6
votes
1 answer

How can I open a file for writing only when it doesn't exist in Perl 6?

According to the open docs, there are adverbs for reading, writing, and appending. That's fine and what I would expect. I have a particular application that uses sysopen for better control and I was trying to rewrite it in Perl 6. I know about…
brian d foy
  • 129,424
  • 31
  • 207
  • 592
6
votes
3 answers

Perl6: Match elements in a list with another list

I have a list of numbers L. There is another list of numbers M. I need to return a list L' of numbers found in both L and M. Edit: Mathematically, I am looking for Multiset intersection. Example: L = 3, 1, 4, 1, 5, 9, 2, 6 M = 9, 7, 1, 2, 1,…
Anant
  • 222
  • 2
  • 8
6
votes
2 answers

What is the difference in contexts in nested and non-nested maps in Perl 6?

I have this bit of code. The first, non-nested map outputs some stuff, and the nested one doesn't. I think I understand why the second doesn't work. It's a lazy sequence and Perl 6 is gathering the results. That's fine. But isn't the first…
brian d foy
  • 129,424
  • 31
  • 207
  • 592
6
votes
2 answers

How can I use a non-caching infinite lazy list in Perl 6

Infinite lazy lists are awesome! > my @fibo = 0, 1, *+* ... *; > say…
mscha
  • 6,509
  • 3
  • 24
  • 40
6
votes
2 answers

perl6 IO::Handle has no printf method, inconsistent with documentation, or I missed something?

I am trying to open a file for writing and use printf to do formatting, but documentation and reality do not seem to agree. Am I missing something? To exit type 'exit' or '^D' > my $fh=open "test", :w; IO::Handle<"test".IO>(opened, at octet 0) >…
lisprogtor
  • 5,677
  • 11
  • 17
6
votes
1 answer

How do make make subroutine parameter as readwrite

Suppose I have a subroutine that swaps two given parameters. It logically needs to have read write parameters. sub swap($l, $r) { my $tmp = $l; $l=$r; $r=$tmp; } I get the error: Cannot assign to a read only variable ($l) or a value I…
tejas
  • 1,795
  • 1
  • 16
  • 34
6
votes
1 answer

perl6 Is using junctions in matching possible?

Is it possible to use junction to match any of the values in a junction? I want to match any of the values in an array. What is the proper way to do it? lisprog$ perl6 To exit type 'exit' or '^D' > my @a= [a b c] > any(@a) any(a, b, c) > my…
lisprogtor
  • 5,677
  • 11
  • 17
6
votes
1 answer

perl6 How to read from stdin and take command line args?

I need to pipe the result of "cat variousFiles" to a perl6 program while requiring the program to take different command line arguments. Perl6 seems to want to take the first argument as a file to be read. I can re-write my routines, but I want to…
lisprogtor
  • 5,677
  • 11
  • 17
6
votes
1 answer

perl6: how to specify multiple requirements for a parameter of a function?

I have a special function that takes a list, each member of the list must satisfy multiple requirements. How do I set this up in a perl6 function? sub specialFunc(List $x) {}; $x is a list # easy, List $x, but what about the following: each member…
lisprogtor
  • 5,677
  • 11
  • 17
6
votes
1 answer

perl6 grammar actions: unable to make anything if not using $/

I wrote a test program, and now it seems that if I don't use $/ in a method signature because I have to use .match inside the method, I can no long make anything. What did I do wrong? A further question is that if .match sets $/, and $/ is…
lisprogtor
  • 5,677
  • 11
  • 17
6
votes
4 answers

perl6 rakudo 2016.11 match tries to assign to read-only variable, why not in 2016.07?

I have the following method in an action class that worked well in Rakudo 2016.07, but I just installed 2016.11 and now the new Rakudo says my method tries to assign to read-only varible, and I just don't see the problem: method ptName ($/) { …
lisprogtor
  • 5,677
  • 11
  • 17
6
votes
1 answer

Should Raku run MAIN if the file is required?

Here's a short Raku program that declare a MAIN subroutine. I should only see output if I execute the program directly: $ cat main.rakumod sub MAIN { say "Called as a program!" } And I see output when I execute the program directly: $ raku…
brian d foy
  • 129,424
  • 31
  • 207
  • 592
6
votes
2 answers

Override Attribute of a Role

Is it possible to override an attribute of a role to provide a default? role A { has $.a; } class B does A { has $.a = "default"; } my $b = B.new; This results in a compile error: ===SORRY!=== Error while compiling: Attribute '$!a' already…
J Hall
  • 531
  • 3
  • 10