raku

How many ways are there to describe the Fibonacci sequence in Perl 6?

馋奶兔 提交于 2019-12-02 18:13:20
I've been looking at the various ways of constructing lazy lists in Perl 6 and I would like to collect all of the concise ways of describing the Fibonacci sequence. I will start this off with the three from masak 's journal: my @fibs := (0, 1, -> $a, $b { $a + $b } ... *); my @fibs := (0, 1, { $^a + $^b } ... *); my @fibs := (0, 1, *+* ... *); I was thinking something like this would also work, but I think I have the syntax wrong: my @fibs := (0, 1, (@fibs Z+ @fibs[1..*])); Something there is eager (the slice?) and causes Rakudo to enter an infinite loop. It's a translation of the Haskell

What's the deal with all the different Perl 6 equality operators? (==, ===, eq, eqv, ~~, =:=, …)

爷,独闯天下 提交于 2019-12-02 17:54:05
Perl 6 seems to have an explosion of equality operators. What is =:= ? What's the difference between leg and cmp ? Or eqv and === ? Does anyone have a good summary? =:= tests if two containers (variables or items of arrays or hashes) are aliased, ie if one changes, does the other change as well? my $x; my @a = 1, 2, 3; # $x =:= @a[0] is false $x := @a[0]; # now $x == 1, and $x =:= @a[0] is true $x = 4; # now @a is 4, 2, 3 As for the others: === tests if two references point to the same object, and eqv tests if two things are structurally equivalent. So [1, 2, 3] === [1, 2, 3] will be false

Filtering elements of an array with elements of another array in Perl 6

最后都变了- 提交于 2019-12-01 17:41:53
问题 I want to filter elements of @array which begin with elements of @search : my @array = "aaaaa" .. "fffff"; my @search = "aaaa" .. "cccc"; .put for @array .grep: /^ @search /; The problem is it takes 19 seconds. So, I 'precompile' the regex for grep , and the whole program looks like this: my @array = "aaaaa" .. "fffff"; my @search = "aaaa" .. "cccc"; my $search = "/@search.join('|')/".EVAL; .put for @array .grep: * ~~ /^ <$search> /; Now it takes 0.444s. The question: is there a built-in Perl

How should I handle Perl 6 $*ARGFILES that can't be read by lines()?

£可爱£侵袭症+ 提交于 2019-12-01 15:34:43
I'm playing around with lines which reads lines from the files you specify on the command line: for lines() { put $_ } If it can't read one of the filenames it throws X::AdHoc (one day maybe it will have better exception types so we can grab the filename with a .path method). Fine, so catch that: try { CATCH { default { put .^name } } for lines() { put $_ } } So this catches the X::AdHoc error but that's it. The try block is done at that point. It can't .resume and try the next file: try { CATCH { default { put .^name; .resume } } # Nope for lines() { put $_ } } Back in Perl 5 land you get a

How should I handle Perl 6 $*ARGFILES that can't be read by lines()?

三世轮回 提交于 2019-12-01 15:19:22
问题 I'm playing around with lines which reads lines from the files you specify on the command line: for lines() { put $_ } If it can't read one of the filenames it throws X::AdHoc (one day maybe it will have better exception types so we can grab the filename with a .path method). Fine, so catch that: try { CATCH { default { put .^name } } for lines() { put $_ } } So this catches the X::AdHoc error but that's it. The try block is done at that point. It can't .resume and try the next file: try {

Terminal ANSI colors does not work with Inline::Perl5 (Data::Printer)

时间秒杀一切 提交于 2019-12-01 03:41:00
问题 The following Perl 5 script: use strict; use warnings; use Data::Printer; my @a = (1,2,3,4); p @a; gives output: (note the blue color), whereas this Perl 6 scripts: use Data::Printer:from<Perl5>; my @a = 1,2,3,4; p @a; gives output: [ [0] 1, [1] 2, [2] 3, [3] 4 ] but the numbers are not colored (as for the Perl 5 case above). System information : $ perl --version This is perl 5, version 29, subversion 3 (v5.29.3) built for x86_64-linux $ perl6 -e '.say for $*DISTRO, $*VM, $*PERL.compiler

What's the difference these two function calling conventions?

淺唱寂寞╮ 提交于 2019-12-01 03:15:50
Functions can be called in a couple ways: say(1, 2, 3) # 123 say: 1, 2, 3 # (1, 2, 3) The latter seems to pass a Positional , but apart from that I don't know how else they differ. Are there any differences that are important to know? What types of situations would you use one over the other? jjmerelo As Raiph tells you above, say: is a label. So you didn't say anything (even though you thought you did) and -- outside use of the REPL -- the compiler will complain that your use of <a b c> was useless: say: <a b c>; # OUTPUT: «WARNINGS for <tmp>:␤Useless use of constant value a b c in sink

What's the difference these two function calling conventions?

感情迁移 提交于 2019-12-01 00:14:09
问题 Functions can be called in a couple ways: say(1, 2, 3) # 123 say: 1, 2, 3 # (1, 2, 3) The latter seems to pass a Positional , but apart from that I don't know how else they differ. Are there any differences that are important to know? What types of situations would you use one over the other? 回答1: As Raiph tells you above, say: is a label. So you didn't say anything (even though you thought you did) and -- outside use of the REPL -- the compiler will complain that your use of <a b c> was

Why does constraining a Perl 6 named parameter to a definite value make it a required value?

我们两清 提交于 2019-11-30 23:43:53
问题 Consider these subroutines that all take a single named parameter. Named parameters should be optional and I haven't seen anything to say there are exceptions to that. With no type constraints there's no problem; the named parameter is not required. With a type constraint that can accept a type object (no annotation, :U , and :_ ) there is no problem. Parameter '$quux' of routine 'quux' must be an object instance of type 'Int', not a type object of type 'Int'. Did you forget a '.new'? in sub

Extracting from .bib file with Perl 6

六眼飞鱼酱① 提交于 2019-11-30 04:52:45
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, Bjorn I and Kidd, Mark and Waldum, Helge L and Drozdov, Ignat and Chan, Anthony KC and Modlin, Irvin