perl6

Does Perl 6 have a built-in tool to make a deep copy of a nested data structure?

帅比萌擦擦* 提交于 2019-12-09 11:24:57
问题 Does Perl 6 have a built-in tool to make a deep copy of a nested data structure? Added example: my %hash_A = ( a => { aa => [ 1, 2, 3, 4, 5 ], bb => { aaa => 1, bbb => 2 }, }, ); my %hash_B = %hash_A; #my %hash_B = %hash_A.clone; # same result %hash_B<a><aa>[2] = 735; say %hash_A<a><aa>[2]; # says "735" but would like get "3" 回答1: my %A = ( a => { aa => [ 1, 2, 3, 4, 5 ], bb => { aaa => 1, bbb => 2 }, }, ); my %B = %A.deepmap(-> $c is copy {$c}); # make sure we get a new container instead of

Why is this Perl 6 feed operator a “bogus statement”?

余生颓废 提交于 2019-12-09 03:13:06
问题 I took this example from Day 10 – Feed operators of the Perl 6 2010 Advent Calendar with the slight change of .uc for the .ucfirst that's no longer there: my @rakudo-people = <scott patrick carl moritz jonathan jerry stephen>; @rakudo-people ==> grep { /at/ } ==> map { .uc } ==> my @who-it's-at; say ~@who-it's-at; I write it slightly differently with some additional whitespace: my @rakudo-people = <scott patrick carl moritz jonathan jerry stephen>; @rakudo-people ==> grep { /at/ } ==> map {

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

Where should I catch a Perl 6 warning control exception?

為{幸葍}努か 提交于 2019-12-08 22:17:26
问题 I'm playing around with Perl 6's control exceptions. A warn raises a control exception which is invisible to normal exception control flow, and that exception resumes itself. That's kinda cool. So, playing around with this, I wrote this to see what would happen. I'm not trying to solve a particular problem other than seeing what Perl 6 actually does: use v6; try { CONTROL { put "Caught an exception, in the try"; put .^name; } do-that-thing-you-do(); } sub do-that-thing-you-do { CONTROL { put

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

“Too few positionals” in macro definition

你。 提交于 2019-12-08 18:58:42
问题 I'm trying to create some examples of using (experimental) macros this way: use experimental :macros; macro cards_vars() { (<hearts clubs diamonds spades> X~ 1..10).map: { "my \$$^x = False;" } }; cards_vars(); say $hearts1; This creates and runs the macro, and then checks if one of the variable defined exists. But I get this error: Too few positionals passed; expected 3 arguments but got 2 I don't even know where that error comes from. I think it's in cards_vars(), but I have no idea if that

“Two terms in a row” error

你说的曾经没有我的故事 提交于 2019-12-08 18:53:07
问题 I am trying to write a compact line as below, the code is an extract from a script that reads STDIN by using the dynamically scoped special variable $*IN. Can you please advise how to write this line correctly? This works for $*IN.lines() { last when "" ; say "VERBOSE \"$_ is the string\""; $i=$i+1; } does not work .say "VERBOSE \"$_ is the string\"" for $*IN.lines() last when ""; error output: ===SORRY!=== Error while compiling /usr/share/asterisk/agi-bin/agi-t1.p6 Two terms in a row at /usr

Dynamic variable @*INC not found

淺唱寂寞╮ 提交于 2019-12-08 18:51:06
问题 So I've been trying to get electron working with Perl6 and looks like after all my efforts of hacking things to get them to work, it just doesn't want to do it's thing. I have used the following script (one of the examples from the electron repo on git): #!/usr/bin/env perl6 use v6; use Electron; my $app = Electron::App.instance; LEAVE { $app.destroy if $app.defined; } say Electron::Dialog.show-open-dialog.perl; say Electron::Dialog.show-save-dialog.perl; say Electron::Dialog.show-message-box