Re: Two questions on Perl 6 functionality
I still have several points unclear, this is my sample: ### class Base { method toHash() { return {}; } } role FooBar { has $.foo is rw; has $.bar is rw; toHash.wrap({ my $hash = callsame(); $hashfoo = $self.foo; return $hash; }); } class Compose is Base does FooBar { } my $obj = Compose.new(foo='foovalue', bar='barvalue'); my $data = $obj-toHash;### 1: It tells me toHash is not defined, as the role actually don't has that. 2: It seems that wrapping will affect the closure globally, but I only want class with specific role has specific modification. Date: Sun, 20 Jun 2010 13:53:59 +0200 From: mor...@faui2k3.org To: jianding...@msn.com CC: perl6-users@perl.org Subject: Re: Two questions on Perl 6 functionality Xi Yang wrote: You might mis-understood method modifiers. I mean: before x() after x() around x() In Perl 6, you do that with wrapping: http://perlcabal.org/syn/S06.html#Wrapping Cheers, Moritz _ Hotmail: Powerful Free email with security by Microsoft. https://signup.live.com/signup.aspx?id=60969
RE: Two questions on Perl 6 functionality
You might mis-understood method modifiers. I mean: before x() after x() around x() Date: Sun, 20 Jun 2010 12:17:46 +0200 From: mor...@faui2k3.org To: jianding...@msn.com CC: perl6-users@perl.org Subject: Re: Two questions on Perl 6 functionality Hi, Xi Yang wrote: 1: Does Perl 6 has method modifiers like those in Moose? Perl 6 has traits, so you can write for example class A { method x() is rw { ...} } to indicate that it's an lvalue routine (though I don't think it's implemented in Rakudo yet). Where can I get the doc about that? By reading apocalypse? The Apocalypses are of historical interest only. Please read the Synopsis instead http://perlcabal.org/syn/ http://perlcabal.org/syn/S06.html http://perlcabal.org/syn/S12.html 2: Does Perl 6 has build-in support for message passing (like those in Glib and Actionscript)? I fear I'm not qualified to answer that, and I hope somebody else picks up the topic. Cheers, Moritz _ Hotmail: Free, trusted and rich email service. https://signup.live.com/signup.aspx?id=60969
RE: Two questions on Perl 6 functionality
Very subtle implementation, I'm trying to understand those things. Thanks! Date: Sun, 20 Jun 2010 13:53:59 +0200 From: mor...@faui2k3.org To: jianding...@msn.com CC: perl6-users@perl.org Subject: Re: Two questions on Perl 6 functionality Xi Yang wrote: You might mis-understood method modifiers. I mean: before x() after x() around x() In Perl 6, you do that with wrapping: http://perlcabal.org/syn/S06.html#Wrapping Cheers, Moritz _ Hotmail: Free, trusted and rich email service. https://signup.live.com/signup.aspx?id=60969
Severe performance loss, comparing with perl 5
I'm trying to use use Perl 6 to process some nucleotide sequences. However, I found it strangely slow on substr or string concat operations, compared with its Perl 5 equivalent. Here are the codes, Perl 6 on top, Perl 5 on middle, a test input file on bottom (should be stored to makeseq.fasta). The Perl 6's revcom() sub works very slow. #!/usr/bin/perl6use v6;use Bio::SeqIO; say program initialized;my $IN = Bio::SeqIO.new('fasta','makeseq.fasta'); say input stream created; while (my $obj = $IN.next_seq) {say \tid: ,$obj.display_id,; say \tseq: {$obj.seq}; say \trev: {revcom($obj.seq)};} sub revcom(Str $seq) { my $len = $seq.chars; my $result; loop (my $i=$len-1; $i=0; $i--) { given ($seq.substr($i,1)) { when ('A') {$result~='T'} when ('T') {$result~='A'} when ('G') {$result~='C'} when ('C') {$result~='G'} when ('a') {$result~='t'} when ('t') {$result~='a'} when ('g') {$result~='c'} when ('c') {$result~='g'} } } return $result;} #!/usr/bin/perl use strict;use Bio::SeqIO;use feature qw/say switch/; say program initialized; my $IN = Bio::SeqIO-new(-file='makeseq.fasta'); say input stream created; while (my $obj = $IN-next_seq) {say \tid: ,$obj-display_id,;say \tseq: ,$obj-seq,;say \trev: ,revcom($obj-seq),;} sub revcom {my $seq = shift;my $len = length $seq; my $result; for (my $i=$len-1; $i=0; $i--) { given (substr $seq,$i,1) { when ('A') {$result.='T'} when ('T') {$result.='A'} when ('G') {$result.='C'} when ('C') {$result.='G'} when ('a') {$result.='t'} when ('t') {$result.='a'} when ('g') {$result.='c'} when ('c') {$result.='g'} } } return $result;} EMBOSS_001ccgacaacgaatatacgggctgtttgcttgcgtttgagaggtcgtattcccagatgcgtaacgtagcgctccactccgttcgaaaggccggaggaaacaatcgctgaacaactgggtagacataaccatgtcgtctctgtgctactcccccacgggtatattaaggcagataaggttgcttagtgggacctataacEMBOSS_002cggattcagaattggacccggaagcatgcaggcgtggaatgtgggttaagggaccgaagtatttcgttactattccgatagtatccgatgagtccgtagcgggatgcacgtcataatcctagccttgaacgaccgggtactggttacgcaattccacccatgtaccttcccacagcccacatgcgacttattEMBOSS_003tctacgtatgggaataggacgtgctcaatacacgcatggcttgccgtccatcgggagcgttgcaagtcaaagagctaggcttaacctggactgagtggtcattgcgccgatgcacggcctgcctcagcgctgggagtaatcgtcaatagcaagtgtattgtagcgtcatcccaggcctcgaggcctaaEMBOSS_004gttgccgaacgcgccactctcccgcggtgcttaatcgagttggactcaccacctaccacacaacaccggatgcgctaactccgggcatctgtcgcaaggcttcatggaaccctacactggtaatcatggtaatagattcaacgtgggttccgttcatatagacaccactcacaaaggcgttcgtgccctgatEMBOSS_005atatcactcagcctgtggacgtgagccacccgcgctcactctcgctgtagattatgtcagagaacgtagaatctgtaatcatcggtcatatgaagtaatccaccgacaccgagcaacgttgctactgacaacgggacatttaagagtgctggaaattgagttattccgcctggataattggcggtttg _ Hotmail: Trusted email with powerful SPAM protection. https://signup.live.com/signup.aspx?id=60969