perl6

When does for call the iterator method?

痴心易碎 提交于 2019-11-29 15:07:28
This question is in the same ballpark as this other on making blocks iterable , but seems to reveal a different problem with mixins (or a different misunderstanding of the syntax on my part). What Iterable does is to make a data structure effectively iterable, that is, you can create loops by preceding it with for . Iterable serves as an API for objects that can be iterated with the for construct and related iteration constructs, like hyper operators. So let's try to put this to practice: my &logger = -> $event { state %store; if ( $event ) { %store{ DateTime.new( now ) } = $event; } else {

Regex speed in Perl 6

落爺英雄遲暮 提交于 2019-11-29 14:23:56
I've been previously working only with bash regular expressions, grep , sed , awk etc. After trying Perl 6 regexes I've got an impression that they work slower than I would expect, but probably the reason is that I handle them incorrectly. I've made a simple test to compare similar operations in Perl 6 and in bash . Here is the Perl 6 code: my @array = "aaaaa" .. "fffff"; say +@array; # 7776 = 6 ** 5 my @search = <abcde cdeff fabcd>; my token search { @search } my @new_array = @array.grep({/ <search> /}); say @new_array; Then I printed @array into a file named array (with 7776 lines), made a

Use of colon in method and function calls in Perl 6

这一生的挚爱 提交于 2019-11-29 10:45:16
I'm wondering what colons have to do with method and function calls in Perl 6. For the record, I am using perl6 version 2015.05-55-gd84bbbc built on MoarVM version 2015.05. I just saw the following in a Perl6 spec test (S32-io) (I added the comment): $fh.print: "0123456789A"; # prints '0123456789A' to the file As far as I can tell, this is equivalent to: $fh.print("0123456789A"); # prints '0123456789A' to the file Both of these seem to take multiple arguments and to flatten lists fine: $fh.print: "012", "345", "6789A"; # prints '0123456789A' to the file $fh.print("012", "345", "6789A"); #

Extracting from .bib file with Perl 6

一世执手 提交于 2019-11-29 02:23:02
问题 I have this .bib file for reference management while writing my thesis in LaTeX: @article{garg2017patch, title={Patch testing in patients with suspected cosmetic dermatitis: A retrospective study}, author={Garg, Taru and Agarwal, Soumya and Chander, Ram and Singh, Aashim and Yadav, Pravesh}, journal={Journal of Cosmetic Dermatology}, year={2017}, publisher={Wiley Online Library} } @article{hauso2008neuroendocrine, title={Neuroendocrine tumor epidemiology}, author={Hauso, Oyvind and Gustafsson

How do I “flatten” a list of lists in perl 6?

断了今生、忘了曾经 提交于 2019-11-29 01:47:42
Let's say I want all permutations of 2 letters out of a, b and c. I can do: my @perm = <a b c>.combinations(2)».permutations; say @perm; # [((a b) (b a)) ((a c) (c a)) ((b c) (c b))] which is close, but not exactly what I need. How do I “flatten” this so that I get: # [(a b) (b a) (a c) (c a) (b c) (c b)] ? raiph See also "a better way to accomplish what I (OP) wanted" . See also "Some possible solutions" answer to "How can I completely flatten a Perl 6 list (of lists (of lists) … )" question . Add a subscript my \perm = <a b c>.combinations(2)».permutations; say perm; # (((a b) (b a)) ((a c)

When does for call the iterator method?

痞子三分冷 提交于 2019-11-28 08:21:16
问题 This question is in the same ballpark as this other on making blocks iterable, but seems to reveal a different problem with mixins (or a different misunderstanding of the syntax on my part). What Iterable does is to make a data structure effectively iterable, that is, you can create loops by preceding it with for . Iterable serves as an API for objects that can be iterated with the for construct and related iteration constructs, like hyper operators. So let's try to put this to practice: my

Don't show declarator blocks with p6doc

时光总嘲笑我的痴心妄想 提交于 2019-11-28 07:22:06
问题 I've written a small example file to learn more about Perl 6 POD, and I'm using p6doc to render a small manual page from the POD document. However, p6doc also tries to parse the declarator blocks outside the POD document. This doesn't look particularly great in the output. Is there a way to ignore the declarator blocks when using p6doc ? The code sample I'm using is: #! /usr/bin/env perl6 use v6.c; #| Greet people on the command line. sub MAIN ( #| A name to greet. $names, #| Optional.

How can I interpolate a variable into a Perl 6 regex?

谁都会走 提交于 2019-11-28 00:03:27
Synopsis 05 mentions that Perl 6 doesn't interpolate variables into a regex, but you can associate an external variable with a pattern. The docs don't mention this feature as far as I can tell. I think people are still going to want to build up a pattern from a string somehow, so I'm curious how that would work. Here's a program that demonstrates what happens now. I don't know if that's what is supposed to happen or what anyone intended. I insert a variable into a pattern. If you look at $r with .perl , you see the variable name. Then, I apply the pattern and it matches. I change the variable

I can create filehandles to strings in Perl 5, how do I do it in Perl 6?

孤者浪人 提交于 2019-11-27 23:32:54
问题 In Perl 5, I can create a filehandle to a string and read or write from the string as if it were a file. This is great for working with tests or templates. For example: use v5.10; use strict; use warnings; my $text = "A\nB\nC\n"; open(my $fh, '<', \$text); while(my $line = readline($fh)){ print $line; } How can I do that in Perl 6? The following doesn't work for Perl 6 (at least not for my instance of Perl6 running on MoarVM 2015.01 from the January 2015 release of Rakudo Star on 64-bit

Is that a Perl 6 Hash or Block?

给你一囗甜甜゛ 提交于 2019-11-27 17:47:51
问题 This is a bit of unexpected behavior that's likely to bite beginners. First, is this intended? Second, what other things does Perl 6 use to guess which object to create? Does it start off thinking it's Block or Hash and change later, or does it decide on the end? You can construct a Hash with braces and the fat arrow: my $color-name-to-rgb = { 'red' => 'FF0000', }; put $color-name-to-rgb.^name; # Hash Using the other Pair notation creates a Hash too. my $color-name-to-rgb = { :red('FF0000'),