How to accomplish a method interpolation?
I'm reading a book "Make your own python text adventure" and decided to give it a try with perl6. So this code works as expected. class Bag { has %.items; method show { say "ropa ", %!items.amount if %!items:exists; say "femur ", %!items.amount if %!items:exists; say "fósforos ", %!items.amount if %!items :exists; } } I'm using a class called bag as my inventory and trying to keep track of items in a hash, so the key is just a name and the value is an object and just found that a pattern when I try to list the elements on the screen... dd %!items Hash %!items = {:femur(Items::Femur.new(amount => 1)), :fósforos(Items::Matches.new(amount => 3)), :ropa(Items::Cloth.new(amount => 4))} Items has data and the show method does what I expect, then I change the code, so I try to add a private method that handdle the pattern and change the show method to use the private one. class Bag { has %.items; method !show-item ($msg, $item, $attr) { # dd $msg; dd $item; dd $attr; # all Str say "$msg ", %items{$item}.$attr if %!items{$item}:exists; } method show { self!show-item('Ropa', 'ropa', 'amount'); ... } } Now I get an error, the line corresponds to the private method No such method 'CALL-ME' for invocant of type 'Str' Try a few variants like return instead of say or things like say "$msg", "%!items{$item}.$attr"; # output: Ropa Items::Cloth<94810994868552>.amount say "$msg", $!items{$item}.{$attr}; # output: Type Items::Cloth does not support associative indexing. say "$msg", %!items{$item}."{$attr}"; # ouput: gives a compile error The output I'm expecting is: Ropa 4 Ropa is the $msg, and 4 corresponds to the value in the attribute amount. Is there a way to refactor my code? Thanks in advance.
[perl #132668] [NATIVECALL][SEGV] OpenSSL PEM_write_bio_RSAPrivateKey
# New Ticket Created by Lloyd Fournier # Please include the string: [perl #132668] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=132668 > I was trying to add RSA key generation using nativecall and OpenSSL but kept getting non-deterministic segfaults. golfed example: #nativessl.pl use NativeCall; sub gen-lib { $*VM.platform-library-name('ssl'.IO).Str } sub RSA_new(-->OpaquePointer) is native() {...} sub RSA_generate_key_ex(OpaquePointer $rsa, int32 $bits, OpaquePointer $e, OpaquePointer $cb --> OpaquePointer) is native() {...} sub BN_new(-->OpaquePointer) is native() {...} sub BN_set_word(OpaquePointer $bn, uint32 $e --> int32) is native() {...} sub BIO_s_mem(-->OpaquePointer) is native() {...} sub PEM_write_bio_RSAPrivateKey(OpaquePointer $bio, OpaquePointer $rsa --> int32) is native(){...} sub BIO_new(OpaquePointer $method --> OpaquePointer) is native(){...}; { my uint32 $bits = 2048; my $bne = BN_new(); BN_set_word($bne, 3) || die; my $rsa = RSA_new(); RSA_generate_key_ex($rsa, $bits, $bne, Nil) || die; my $bio = BIO_new(BIO_s_mem()); PEM_write_bio_RSAPrivateKey($bio, $rsa); } bash-3.2$ while perl6 nativessl.pl; do echo "worked"; done Segmentation fault: 11 bash-3.2$ while perl6 nativessl.pl; do echo "worked"; done worked worked worked worked worked worked Segmentation fault: 11 bash-3.2$ while perl6 nativessl.pl; do echo "worked"; done worked worked worked worked Segmentation fault: 11 bash-3.2$
[perl #131700] [IO] prompt not working on bash-on-ubuntu on win10
On Tue, 04 Jul 2017 06:51:16 -0700, blackcatoverw...@gmail.com wrote: > In bash on win10 > > Code: > > perl6 --ll-exception -e ' prompt "123" ' > > Output: > > 123 > Cannot flush handle: Failed to flush filehandle: Input/output error >at SETTING::src/core/Exception.pm:63 > (/usr/share/perl6/runtime/CORE.setting.moarvm:throw) > from SETTING::src/core/Failure.pm:44 > (/usr/share/perl6/runtime/CORE.setting.moarvm:throw) > from SETTING::src/core/Failure.pm:86 > (/usr/share/perl6/runtime/CORE.setting.moarvm:sink) > from SETTING::src/core/io_operators.pm:89 > (/usr/share/perl6/runtime/CORE.setting.moarvm:prompt) > from SETTING::src/core/io_operators.pm:83 > (/usr/share/perl6/runtime/CORE.setting.moarvm:prompt) > from -e:1 (:) > from -e:1 (:) > from gen/moar/stage2/NQPHLL.nqp:1589 > (/usr/share/nqp/lib/NQPHLL.moarvm:eval) > from gen/moar/stage2/NQPHLL.nqp:1696 (/usr/share/nqp/lib/NQPHLL.moarvm:) > from gen/moar/stage2/NQPHLL.nqp:1731 > (/usr/share/nqp/lib/NQPHLL.moarvm:command_eval) > from src/Perl6/Compiler.nqp:42 > (/usr/share/nqp/lib/Perl6/Compiler.moarvm:command_eval) > from gen/moar/stage2/NQPHLL.nqp:1677 > (/usr/share/nqp/lib/NQPHLL.moarvm:command_line) > from gen/moar/main.nqp:47 (/usr/share/perl6/runtime/perl6.moarvm:MAIN) > from gen/moar/main.nqp:38 > (/usr/share/perl6/runtime/perl6.moarvm:) > from :1 (/usr/share/perl6/runtime/perl6.moarvm:) > from :1 (/usr/share/perl6/runtime/perl6.moarvm:) > > perl6 -v output: > > This is Rakudo version 2017.06 built on MoarVM version 2017.06 > implementing Perl 6.c. Thank you for the report. This is now fixed. Fix: https://github.com/MoarVM/MoarVM/commit/4541cf6f6c https://github.com/perl6/nqp/commit/659ced5b57 https://github.com/rakudo/rakudo/commit/096c4eadbe Test: https://github.com/perl6/roast/commit/dcce881633
[perl #131700] [IO] prompt not working on bash-on-ubuntu on win10
On Tue, 04 Jul 2017 06:51:16 -0700, blackcatoverw...@gmail.com wrote: > In bash on win10 > > Code: > > perl6 --ll-exception -e ' prompt "123" ' > > Output: > > 123 > Cannot flush handle: Failed to flush filehandle: Input/output error >at SETTING::src/core/Exception.pm:63 > (/usr/share/perl6/runtime/CORE.setting.moarvm:throw) > from SETTING::src/core/Failure.pm:44 > (/usr/share/perl6/runtime/CORE.setting.moarvm:throw) > from SETTING::src/core/Failure.pm:86 > (/usr/share/perl6/runtime/CORE.setting.moarvm:sink) > from SETTING::src/core/io_operators.pm:89 > (/usr/share/perl6/runtime/CORE.setting.moarvm:prompt) > from SETTING::src/core/io_operators.pm:83 > (/usr/share/perl6/runtime/CORE.setting.moarvm:prompt) > from -e:1 (:) > from -e:1 (:) > from gen/moar/stage2/NQPHLL.nqp:1589 > (/usr/share/nqp/lib/NQPHLL.moarvm:eval) > from gen/moar/stage2/NQPHLL.nqp:1696 (/usr/share/nqp/lib/NQPHLL.moarvm:) > from gen/moar/stage2/NQPHLL.nqp:1731 > (/usr/share/nqp/lib/NQPHLL.moarvm:command_eval) > from src/Perl6/Compiler.nqp:42 > (/usr/share/nqp/lib/Perl6/Compiler.moarvm:command_eval) > from gen/moar/stage2/NQPHLL.nqp:1677 > (/usr/share/nqp/lib/NQPHLL.moarvm:command_line) > from gen/moar/main.nqp:47 (/usr/share/perl6/runtime/perl6.moarvm:MAIN) > from gen/moar/main.nqp:38 > (/usr/share/perl6/runtime/perl6.moarvm:) > from :1 (/usr/share/perl6/runtime/perl6.moarvm:) > from :1 (/usr/share/perl6/runtime/perl6.moarvm:) > > perl6 -v output: > > This is Rakudo version 2017.06 built on MoarVM version 2017.06 > implementing Perl 6.c. Thank you for the report. This is now fixed. Fix: https://github.com/MoarVM/MoarVM/commit/4541cf6f6c https://github.com/perl6/nqp/commit/659ced5b57 https://github.com/rakudo/rakudo/commit/096c4eadbe Test: https://github.com/perl6/roast/commit/dcce881633
[perl #130613] [OPTIMIZER][LTA] "if" without "else" much slower than "if" with empty "else"
On Sat, 21 Jan 2017 11:45:10 -0800, ale...@yahoo.com wrote: > Take a look at the following examples - the second is more than > 10x(!!!) faster: > m: my int $i = 0; loop { if $i++ == 10_000_000 { last }}; say now - > INIT now;rakudo-moar f97d5c: OUTPUT«2.0606382» > m: my int $i = 0; loop { if $i++ == 10_000_000 { last } else {} }; say > now - INIT now; > rakudo-moar f97d5c: OUTPUT«0.1727145» > > In my understanding of > https://github.com/rakudo/rakudo/blob/nom/src/Perl6/Actions.nqp#L1675 > the first example is equivalent to: > > m: my int $i = 0; loop { if $i++ == 10_000_000 { last } else { Empty } > }; say now - INIT now; > rakudo-moar f97d5c: OUTPUT«WARNINGS for :Useless use of constant > value Empty in sink context (line 1)2.120407471» Thank you for the report. This is now fixed. The `else`-less version is now nearly twice faster: $ ./perl6 -e 'm: my int $i = 0; loop { if $i++ == 10_000_000 { last }}; say now - INIT now;' 0.09784453 $ ./perl6 -e 'm: my int $i = 0; loop { if $i++ == 10_000_000 { last } else {} }; say now - INIT now;' 0.1641829 Fix: https://github.com/rakudo/rakudo/commit/1815c36843ac58f Closing without tests, since AFAIK we haven't figured out how to cover perf issues well yet.
[perl #130613] [OPTIMIZER][LTA] "if" without "else" much slower than "if" with empty "else"
On Sat, 21 Jan 2017 11:45:10 -0800, ale...@yahoo.com wrote: > Take a look at the following examples - the second is more than > 10x(!!!) faster: > m: my int $i = 0; loop { if $i++ == 10_000_000 { last }}; say now - > INIT now;rakudo-moar f97d5c: OUTPUT«2.0606382» > m: my int $i = 0; loop { if $i++ == 10_000_000 { last } else {} }; say > now - INIT now; > rakudo-moar f97d5c: OUTPUT«0.1727145» > > In my understanding of > https://github.com/rakudo/rakudo/blob/nom/src/Perl6/Actions.nqp#L1675 > the first example is equivalent to: > > m: my int $i = 0; loop { if $i++ == 10_000_000 { last } else { Empty } > }; say now - INIT now; > rakudo-moar f97d5c: OUTPUT«WARNINGS for :Useless use of constant > value Empty in sink context (line 1)2.120407471» Thank you for the report. This is now fixed. The `else`-less version is now nearly twice faster: $ ./perl6 -e 'm: my int $i = 0; loop { if $i++ == 10_000_000 { last }}; say now - INIT now;' 0.09784453 $ ./perl6 -e 'm: my int $i = 0; loop { if $i++ == 10_000_000 { last } else {} }; say now - INIT now;' 0.1641829 Fix: https://github.com/rakudo/rakudo/commit/1815c36843ac58f Closing without tests, since AFAIK we haven't figured out how to cover perf issues well yet.
Re: Module wishlist priorities
https://github.com/perl6/perl6-most-wanted/blob/master/most-wanted/modules.md ~ Michael D. Stemle, Jr. > On Dec 29, 2017, at 15:22, Simon Proctorwrote: > > Where is the wishlist? > >> On Fri, 29 Dec 2017 at 20:12 Michael Stemle wrote: >> I just finished a module from the wishlist. I’d like to pick up another. Is >> this a good place to discuss priorities for the existing wishlist, or in >> general? >> >> I didn’t see an obvious list for this topic. >> >> Many thanks. >> >> ~ Michael D. Stemle, Jr.
Re: Module wishlist priorities
Where is the wishlist? On Fri, 29 Dec 2017 at 20:12 Michael Stemlewrote: > I just finished a module from the wishlist. I’d like to pick up another. > Is this a good place to discuss priorities for the existing wishlist, or in > general? > > I didn’t see an obvious list for this topic. > > Many thanks. > > ~ Michael D. Stemle, Jr.
Module wishlist priorities
I just finished a module from the wishlist. I’d like to pick up another. Is this a good place to discuss priorities for the existing wishlist, or in general? I didn’t see an obvious list for this topic. Many thanks. ~ Michael D. Stemle, Jr.
[perl #132666] [REGEX] [PARSER] Escaped hash character `\#` is somtimes parsed incorrectly
On Fri, 29 Dec 2017 07:05:29 -0800, sml...@gmail.com wrote: > These regexes parse and run fine (they match a single `#` character): > > /\#/; > /^\#/; > > But this one doesn't: > > /^ \#/; > > The error thrown, is: > > ===SORRY!=== > Regex not terminated. > at -e:1 > --> /^ \#/⏏ > Unable to parse regex; couldn't find final '/' > at -e:1 > --> /^ \#/⏏ > expecting any of: > infix stopper > > It's as if the parser fails to recognize that the `#` character was > escaped (interpreting the backslash as unspace maybe?), and treats > everything until the end of the line as a comment. > > This seems to be only happening when the escaped `#` character is > preceded by another token, *and* separated from it by whitespace. > > Apparently this bug has always existed in Rakudo: > https://gist.github.com/Whateverable/ca082a33d2ab689bf3ca4b6f7ae2d19f Thank you for the report. This is a duplicate of https://github.com/rakudo/rakudo/issues/1324 The problematic cases are matched[^1] as unspaces. The `\#` thing was never meant[^2] to work, but it slipped through and now we probably have to deal with back-compat issues in order to fix it. [1] https://github.com/rakudo/rakudo/issues/1324#issuecomment-353233051 [2] https://github.com/rakudo/rakudo/issues/1324#issuecomment-353435175
[perl #132666] [REGEX] [PARSER] Escaped hash character `\#` is somtimes parsed incorrectly
On Fri, 29 Dec 2017 07:05:29 -0800, sml...@gmail.com wrote: > These regexes parse and run fine (they match a single `#` character): > > /\#/; > /^\#/; > > But this one doesn't: > > /^ \#/; > > The error thrown, is: > > ===SORRY!=== > Regex not terminated. > at -e:1 > --> /^ \#/⏏ > Unable to parse regex; couldn't find final '/' > at -e:1 > --> /^ \#/⏏ > expecting any of: > infix stopper > > It's as if the parser fails to recognize that the `#` character was > escaped (interpreting the backslash as unspace maybe?), and treats > everything until the end of the line as a comment. > > This seems to be only happening when the escaped `#` character is > preceded by another token, *and* separated from it by whitespace. > > Apparently this bug has always existed in Rakudo: > https://gist.github.com/Whateverable/ca082a33d2ab689bf3ca4b6f7ae2d19f Thank you for the report. This is a duplicate of https://github.com/rakudo/rakudo/issues/1324 The problematic cases are matched[^1] as unspaces. The `\#` thing was never meant[^2] to work, but it slipped through and now we probably have to deal with back-compat issues in order to fix it. [1] https://github.com/rakudo/rakudo/issues/1324#issuecomment-353233051 [2] https://github.com/rakudo/rakudo/issues/1324#issuecomment-353435175
[perl #131243] [REGEX] Interpolating a Hash in a regex treats it as a list and errors out
On Tue, 02 May 2017 08:35:34 -0700, c...@zoffix.com wrote: > Both of these forms produce the error below > > my %stuff = ; > say 'foo bar meows' ~~ m:g/ %stuff\S+ /; > say 'foo bar meows' ~~ m:g/ %() \S+ /; > > # P6opaque: no such attribute '$!reified' in type List when trying to > get > # a value in block at z2.p6 line 8 > > What did I expect to happen? No idea, I just randomly tried the code. > If it's not meant to work then at least a better error should be > shown. S05 says¹: The use of a hash variable in patterns is reserved. So yes, this should be made to throw a nicer error. --- [1] http://design.perl6.org/S05.html#Variable_(non-)interpolation
[perl #132666] [REGEX] [PARSER] Escaped hash character `\#` is somtimes parsed incorrectly
# New Ticket Created by Sam S. # Please include the string: [perl #132666] # in the subject line of all future correspondence about this issue. # https://rt.perl.org/Ticket/Display.html?id=132666 > These regexes parse and run fine (they match a single `#` character): /\#/; /^\#/; But this one doesn't: /^ \#/; The error thrown, is: ===SORRY!=== Regex not terminated. at -e:1 --> /^ \#/⏏ Unable to parse regex; couldn't find final '/' at -e:1 --> /^ \#/⏏ expecting any of: infix stopper It's as if the parser fails to recognize that the `#` character was escaped (interpreting the backslash as unspace maybe?), and treats everything until the end of the line as a comment. This seems to be only happening when the escaped `#` character is preceded by another token, *and* separated from it by whitespace. Apparently this bug has always existed in Rakudo: https://gist.github.com/Whateverable/ca082a33d2ab689bf3ca4b6f7ae2d19f