raku

Alter how arguments are processed before they're passed to sub MAIN

别说谁变了你拦得住时间么 提交于 2020-07-20 11:07:27
问题 Given the documentation and the comments on an earlier question, by request I've made a minimal reproducible example that demonstrates a difference between these two statements: my %*SUB-MAIN-OPTS = :named-anywhere; PROCESS::<%SUB-MAIN-OPTS><named-anywhere> = True; Given a script file with only this: #!/usr/bin/env raku use MyApp::Tools::CLI; and a module file in MyApp/Tools called CLI.pm6: #PROCESS::<%SUB-MAIN-OPTS><named-anywhere> = True; my %*SUB-MAIN-OPTS = :named-anywhere; proto MAIN(|)

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

喜你入骨 提交于 2020-07-08 05:48:30
问题 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 the container's default value or Any to determine if the linked list's end has been reached. However, I'd still like to use Nil (if only for its clear intent) and no other value to test for the non-existence of a next node in the code (e.g.,

Defined vs. exists with Perl6 hash keys

萝らか妹 提交于 2020-07-06 10:58:33
问题 I am learning Perl6 from Perl5. I am looking at the adverb :exists https://docs.perl6.org/type/Hash#:exists but there isn't a :defined adverb but I am concerned because there is a distinction between perl5's exists & defined : What's the difference between exists and defined? How can I do something like this in Perl6? if (defined $hash{key}) { $hash{key}++; } else { $hash{key} = 1; } 回答1: if defined %hash{'key'} { %hash{'key'}++; } else { %hash{'key'} = 1; } Use the defined routine or method.

Perl6: Adding a sigil with Slangs

孤者浪人 提交于 2020-06-27 07:40:25
问题 I am trying to add «€» as an alias for the «$» scalar, and doing it with a Slang is the way to do it I think. But perl6.doc doesn't mention Slangs at all. I have read the following: https://perlgeek.de/en/article/mutable-grammar-for-perl-6 (from 2008) https://mouq.github.io/slangs.html And looked at the Slang::Roman and Slang::Tuxic modules. The result is this file (ScalarEU.pm6): use nqp; unit module ScalarEU2; sub EXPORT(|) { my role Euscalar { token sigil:sym<$> { '€' | '$' } } my Mu $MAIN

Blob.decode with replacement does not seem to work

China☆狼群 提交于 2020-06-27 07:32:10
问题 This code: my $þor-blob = Blob.new("þor".ords); $þor-blob.decode( "ascii", :replacement("0"), :strict(False) ).say Fails with: Will not decode invalid ASCII (code point > 127 found)␤ And this one: my $euro = Blob.new("3€".ords); $euro.decode( "latin1", :replacement("euro") ).say Simply does not seem to work, replacing € by ¬. It's true that those methods are not tested, but is the syntax right? 回答1: TL;DR : Only samcv or some other core dev can provide an authoritative answer. This is my

When is “race” worthwhile in Perl 6?

那年仲夏 提交于 2020-06-27 07:21:31
问题 race divides operations on an iterable automatically into threads. For instance, (Bool.roll xx 2000).race.sum would automatically divide the sum of the 2000-long array into 4 threads. However, benchmarks show that this is much slower than if race were not employed. This happens even if you make the array bigger. This happens even as the non-autothreaded version gets faster and faster with each version. (Auto-threading also gets faster, but is still twice as slow as not using it.) So the

When is “race” worthwhile in Perl 6?

 ̄綄美尐妖づ 提交于 2020-06-27 07:20:49
问题 race divides operations on an iterable automatically into threads. For instance, (Bool.roll xx 2000).race.sum would automatically divide the sum of the 2000-long array into 4 threads. However, benchmarks show that this is much slower than if race were not employed. This happens even if you make the array bigger. This happens even as the non-autothreaded version gets faster and faster with each version. (Auto-threading also gets faster, but is still twice as slow as not using it.) So the

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

大兔子大兔子 提交于 2020-06-27 07:16:32
问题 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 perfectly: multi MAIN( 'config', 'add', *@hostnames ) { However if I make this a non-slurpy array, this is either not recognized or I don't know how to provide it from the command line: multi MAIN( 'config', 'add', @hostnames ) { I would expect one

Which shell does Perl 6's shell() use?

百般思念 提交于 2020-06-27 07:13:12
问题 Perl 6's shell sends commands to the "shell" but doesn't say what that is. I consistently get bash on my machine but I don't know if I can rely on that. $ perl6 -e 'shell( Q/echo $SHELL/ )' /bin/bash $ csh % perl6 -e 'shell( Q/echo $SHELL/ )' /bin/bash % zsh $ perl6 -e 'shell( Q/echo $SHELL/ )' /bin/bash That's easy enough on Unix when it's documented, but what about cmd.exe or PowerShell on Windows (or bash if it's installed)? I figure it's the cmd.exe but a documented answer would be nice.

How can I view the contents of a hash in Perl6 (in a fashion similar to the Perl 5 modules Data::Dump or Data::Show)?

风流意气都作罢 提交于 2020-06-27 07:07:05
问题 In Perl 5, if I want to see the contents of a hash, I can use Data::Show, Data::Dump, or Data::Dumper. For example: use Data::Show; my %title_for = ( 'Book 1' => { 'Chapter 1' => 'Introduction', 'Chapter 2' => 'Conclusion', }, 'Book 2' => { 'Chapter 1' => 'Intro', 'Chapter 2' => 'Interesting stuff', 'Chapter 3' => 'Final words', } ); show(%title_for); Which outputs: ======( %title_for )======================[ 'temp.pl', line 15 ]====== { "Book 1" => { "Chapter 1" => "Introduction", "Chapter 2