raku

Multiple MAIN signatures

丶灬走出姿态 提交于 2019-12-10 12:57:37
问题 I have a package with multiple main and I want to define several options: My code is something like this: package Perl6::Documentable::CLI { proto MAIN(|) is export {*} my %*SUB-MAIN-OPTS = :named-everywhere; multi MAIN( "setup" ) { ... } multi MAIN ( "start" , Str :$topdir = "doc", Bool :v(:verbose($v)) = False ) { ... } But when I try to actually execute it with: perl6 -Ilib bin/documentable start -v --topdir=ss It outputs this line: Usage: bin/documentable [--topdir=<Str>] [-v|--verbose]

Creating a Maybe type in Perl 6

时光怂恿深爱的人放手 提交于 2019-12-10 12:50:00
问题 I have a lot of functions that can fail, but also have a return type defined in their signature. Since I like defining the types of variables whenever possible, I want to define a Maybe subset to use for this. What I came up with is this: subset Maybe is export of Mu where Mu | Failure; The problem with this is Failure is a subclass of Mu , so this will match anything and everything, when what I really want is to be able to match one specific type along with Failure dynamically. My next

How can I rebuild an edited perl6 module that I've downloaded?

ⅰ亾dé卋堺 提交于 2019-12-10 12:38:08
问题 I've installed Time::Duration and it failed most of its tests. I want to be able to rebuild the module - with my edits - from the locally stored module. I edited the file that contains the module (that corresponds to Duration.pm6): ~/.perl6/sources/D00C101A0157E3EAC494310C9961F299240423E7 And then try building via it's json file: zef --debug build ~/.perl6/dist/83839D8D315EEDEDFEAF211EE42E8D936ACE29CB This returns: ===> # SKIP: No need to build Time::Duration:ver<2.00> !!!> Build failure: ~/

Can only 'perl6' parse Perl 6?

邮差的信 提交于 2019-12-10 12:27:58
问题 There's that (relatively) well known Perl axiom, "Only perl can parse Perl." I'm wondering, will that remain true for Perl 6? Expanding the discussion... I thought of this question given the recent update of PyPy. Does Perl's unique parsability preclude it from similar efforts? Is there much value in a restricted, static view of Perl code (PPI?)? Can Perl 6 have a JIT compiler?* * I'm not sure if these concepts are related. Are they? 回答1: There is no perl6, and there are many Perl 6 compilers

How does one write custom accessor methods in Perl6?

こ雲淡風輕ζ 提交于 2019-12-09 14:45:47
问题 How does one write custom accessor methods in Perl6? If I have this class: class Wizard { has Int $.mana is rw; } I can do this: my Wizard $gandalf .= new; $gandalf.mana = 150; Let's say I want to add a little check to a setter in my Perl6 class without giving up the $gandalf.mana = 150; notation (in other words, I don't want to write this: $gandalf.setMana(150); ). The program should die, if it tries to set a negative mana. How do I do this? The Perl6 documentation just mentions it is

Is there a purpose or benefit in prohibiting sigilless variables from rebinding?

梦想的初衷 提交于 2019-12-09 02:46:27
问题 In trying to better understand sigilless variables and how they differ from $ sigiled variables, I discovered that, unlike $ sigiled variables, sigilless variables cannot be rebound after they've been initialized: my $a = 42; my $b := $a; $b := 42; # No exception generated my \c := $a; c := 42; # OUTPUT: «Cannot use bind operator with this left-hand side␤» Is this by design? If so, is there a purpose or benefit to prohibiting sigilless variables from rebinding when $ sigiled variables are not

perl6 grammar , not sure about some syntax in an example

不想你离开。 提交于 2019-12-09 02:22:00
问题 I am still learning perl6, and I am reading the example on grammar from this page: http://examples.perl6.org/categories/parsers/SimpleStrings.html ; I have read the documentations on regex multiple times, but there are still some syntax that I don't understand; can anyone enlighten me? Thank you very much !!! token string { <quote> {} <quotebody($<quote>)> $<quote> } Question 1: what is this "{}" in the token doing? Capture marker is <()>, and nesting structures is tilda '(' ~ ')'; but what

In perl6, how do you read a file in paragraph mode?

感情迁移 提交于 2019-12-08 19:53:56
问题 data.txt: hello world goodbye mars goodbye perl6 hello perl5 myprog.py: my $fname = 'data.txt'; my $infile = open($fname, :r, nl => "\n\n"); for $infile.lines(nl => "\n\n") -> $para { say $para; say '-' x 10; } Actual output: hello world ---------- goodbye mars ---------- ---------- goodbye perl6 ---------- back to perl5 ---------- Desired output: hello world goodbye mars ----------- goodbye perl6 back to perl5 ----------- ... $ perl6 -v This is perl6 version 2015.03-21-gcfa4974 built on

How to export %*SUB-MAIN-OPTS

泄露秘密 提交于 2019-12-08 19:18:22
问题 Assuming there is a Module that contains the sub MAIN 's which is supposed to improve the startup speed. Unfortunately I am unable to use the named-anywhere feature that way. Is my export broken or what am I supposed to do? use v6.c; unit module My::Main; our %*SUB-MAIN-OPTS is export = ( 'named-anywhere' => True); multi sub MAIN() is export { say 1; } multi sub MAIN('a', :$pa) is export { say $pa; } 回答1: You cannot currently export dynamic variables that way, and maybe we never will. In the

More concise way to build a configuration class using environment variables?

点点圈 提交于 2019-12-08 17:22:34
问题 I have a class Configuration that reads in environment variables: class Configuration { has $.config_string_a; has $.config_string_b; has Bool $.config_flag_c; method new() { sub assertHasEnv(Str $envVar) { die "environment variable $envVar must exist" unless %*ENV{$envVar}:exists; } assertHasEnv('CONFIG_STRING_A'); assertHasEnv('CONFIG_STRING_B'); assertHasEnv('CONFIG_FLAG_C'); return self.bless( config_string_a => %*ENV{'CONFIG_STRING_A'}, config_string_b => %*ENV{'CONFIG_STRING_B'}, config