perl6

Storing intermediate data in a file in Perl 6

五迷三道 提交于 2019-12-10 12:42:22
问题 Some of my programs consist of two parts. First, they read large data from files and transform it, producing Array s, Hash es, Object s etc.; second, they analyse this data with (always different) user-defined conditions. The first part remains the same (as long as the source data isn't changed), but sometimes it takes considerable time to work every time I run the program, and I usually have to run it many times with the same source data. It would be much better to have two programs — one of

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: ~/

multi sub on Array of Int vs Array of Array of Int

我是研究僧i 提交于 2019-12-10 09:56:29
问题 I'd like to have a multi sub where one is for an array of Ints and the other multi sub is for an array of array of Ints. This seems to do the trick: multi sub abc(Int @array) { say 10; } multi sub abc(Array[Int] @array) { say 20; } But, building literals that satisfy those constraints is quite verbose: abc Array[Int].new([1,2,3]); # -> 10 abc Array[Array[Int]].new([Array[Int].new([1,2,3]), Array[Int].new([2,3,4])]); # -> 20 Ideally, I'd be able to just say: abc [1,2,3] abc [[1,2,3], [2,3,4]]

How to remove diacritics in Perl 6

只愿长相守 提交于 2019-12-10 04:33:53
问题 Two related questions. Perl 6 is so smart that it understands a grapheme as one character, whether it is one Unicode symbol (like ä , U+00E4 ) or two and more combined symbols (like p̄ and ḏ̣ ). This little code my @symb; @symb.push("ä"); @symb.push("p" ~ 0x304.chr); # "p̄" @symb.push("ḏ" ~ 0x323.chr); # "ḏ̣" say "$_ has {$_.chars} character" for @symb; gives the following output: ä has 1 character p̄ has 1 character ḏ̣ has 1 character But sometimes I would like to be able to do the following

Perl 6 Grammar doesn't match like I think it should

…衆ロ難τιáo~ 提交于 2019-12-10 04:26:46
问题 I'm doing Advent of Code day 9: You sit for a while and record part of the stream (your puzzle input). The characters represent groups - sequences that begin with { and end with } . Within a group, there are zero or more other things, separated by commas: either another group or garbage. Since groups can contain other groups, a } only closes the most-recently-opened unclosed group - that is, they are nestable. Your puzzle input represents a single, large group which itself contains many

What's an “additional tie breaker” for Perl 6 longest token matching?

喜你入骨 提交于 2019-12-10 03:52:10
问题 The docs for Perl 6 longest alternation in regexes punt to Synopsis 5 to document the rules for longest token matching. There are three rules if different alternatives would match a substring of the same length: The longest declarative prefix breaks the tie The highest specificity breaks the tie "If it's still a tie, use additional tie-breakers." The left most alternation finally wins It's that third rule that I'm curious about. 回答1: First the way the text is organized makes clear that the

perl6 User-defined comparison function in set opertions

冷暖自知 提交于 2019-12-10 02:56:31
问题 Perl6 documentation indicated that when comparing two items in a set, === is used. This is quote from perl6 documentation: Objects/values of any type are allowed as set elements. Within a Set, every element is guaranteed to be unique (in the sense that no two elements would compare positively with the === operator) I am wondering if it is possible to use a user-defined function instead of === ? E.g., How can I use ~~ instead of === in determining whether 2 elements in a set are "equal". The

Why aren't // and m// exactly synonymous?

筅森魡賤 提交于 2019-12-10 02:45:09
问题 From the examples below, I see that / / and m/ / aren't exactly synonymous, contrary to what I expected. I thought that the only reason to use m/ / instead of / / was that it allows using different delimiters (e.g. m{ } ). Why are they different and why would I want to use one versus the other? I am searching for CSV files in a directory. At first I searched for files ending in csv , thus (all code shown as seen from the Perl 6 REPL): > my @csv_files = dir( test => / csv $ / ); ["SampleSheet

What does duckmap really do?

谁说我不能喝 提交于 2019-12-10 02:18:57
问题 From the documentation duckmap will apply &block on each element and return a new list with defined return values of the block. For undefined return values, duckmap will try to descend into the element if that element implements Iterable . But then: my $list = [[1,2,3],[[4,5],6,7]]; say $list.deepmap( *² ); # [[1 4 9] [[16 25] 36 49]] say $list.duckmap( *² ); # [9 9] deepmap behaves pretty much as expected, but I can't really make any sense of what duckmap is doing. This question is related

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