hyperoperator bug? «~» != <<~>>
I was playing with this code: https://github.com/Keith-S-Thompson/fizzbuzz-polyglot/blob/master/fizzbuzz.pl6 [~](((1..100).map: { $_ % 15 == 0 ?? "FizzBuzz" !! $_ % 3 == 0 ?? "Fizz" !! $_ % 5 == 0 ?? "Buzz" !! $_ })«~»("\n")).print; I was cleaning it up and since not everyone can type guillemets, I wound up with this: [~](((1..100).map: { $_ %% 15 ?? "FizzBuzz" !! $_ %% 3 ?? "Fizz" !! $_ %% 5 ?? "Buzz" !! $_ })<<~>>("\n")).print; That generated this error: No such method 'postcircumfix:<( )>' for invocant of type 'Parcel' in at src/gen/BOOTSTRAP.pm:852 in any at src/gen/BOOTSTRAP.pm:836 in block at fizzbuzz.p6:6 Reverting to guillemets fixes the problem. Is this a Rakudo bug or are double angle brackets not interchangeable with guillemets? bin/perl6 -v This is perl6 version 2013.01 built on parrot 4.10.0 revision 0 Cheers, Ovid -- Twitter - http://twitter.com/OvidPerl/ Buy my book - http://bit.ly/beginning_perl Buy my other book - http://www.oreilly.com/catalog/perlhks/ Live and work overseas - http://www.overseas-exile.com/
Hangman in Perl 6
I wrote a hangman game in Perl 6. Suggestions are very welcome. Some issues with it are from things I don't understand. Others are due to bugs or limitations in Rakudo. http://use.perl.org/~Ovid/journal/38191 All in all, I'm quite pleased with how things are coming along. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: Perl 6 pos() function?
- Original Message > From: Daniel Ruoso > my $word = 'banana'; > my @guess = ; > $word ~~ /a/; > @guess[$/.from] = 'a'; > say @guess; So far my workarounds for this problem are failing because as soon as you take your code and refactor: my $word = 'banana'; my @guess = < ? ? ? ? ? ? >; my $letter = 'a'; $word ~~ / <$letter> /; @guess[$/.from] = $letter; say @guess; (I *think* that's the correct syntax?) But that gives the following error: Statement not terminated properly at line 4, near "$letter> /" Revision 34446 on OS X Darwin. Is this a known failure? I think it's not supposed to work yet, but I unsure from the tests. If that's the case, the only work around I can think of is to split the word and individually compare each letter's ord() value. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog- http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Perl 6 pos() function?
I'm trying to replicate the following behavior in Perl 6, but can't figure out a "natural" way to do this (the task is filling in guessed letters for a hangman game): while ( $word =~ /$letter/g ) { $guess[ pos($word) - 1 ] = $letter; } What would be the "canonical" Perl 6 way of doing this? Preferably one which works with the current state of Rakudo :) Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Tech blog - http://use.perl.org/~Ovid/journal/ Twitter - http://twitter.com/OvidPerl Official Perl 6 Wiki - http://www.perlfoundation.org/perl6
Re: am I doing something wrong - hanoi example with 0.5.1 parrot release
--- Ovid <[EMAIL PROTECTED]> wrote: > This line? > > my $ndisks := @*ARGS[0] // 3; > > I was rather under the impression that perl6 does not yet implement > @*ARGS. Unfortunately, I not only cannot recall where I read that, I > don't know where to look to verify that. Er, just to make me feel like a complete idiot ... I was perusing the parrotsketch IRC logs and for the JAN 1 log (http://www.parrotcode.org/misc/parrotsketch-logs/irclog.parrotsketch-200801/irclog.parrotsketch.20080101) I see the following: * added a 'make perl6' target to generate a standalone executable with pbc_to_ex e * added @*ARGS support, so hanoi.pl now runs Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Perl and CGI - http://users.easystreet.com/ovid/cgi_course/ Personal blog - http://publius-ovidius.livejournal.com/ Tech blog - http://use.perl.org/~Ovid/journal/
Re: am I doing something wrong - hanoi example with 0.5.1 parrot release
--- Aaron Trevena <[EMAIL PROTECTED]> wrote: > running the example at > http://svn.pugscode.org/pugs/examples/algorithms/hanoi.pl > > parrot ~/downloads/parrot-0.5.1/languages/perl6/perl6.pbc hanoi.pl > > I get.. > > Null PMC access in isa() > current instr.: 'parrot;Perl6Object;make_proto' pc 55 > (src/gen_builtins.pir:76) > called from Sub 'parrot;Bool;onload' pc 378 > (src/gen_builtins.pir:308) > called from Sub 'parrot;Perl6::Compiler;main' pc -1 ((unknown > file):-1) > > Am I doing something wrong? This line? my $ndisks := @*ARGS[0] // 3; I was rather under the impression that perl6 does not yet implement @*ARGS. Unfortunately, I not only cannot recall where I read that, I don't know where to look to verify that. Cheers, Ovid -- Buy the book - http://www.oreilly.com/catalog/perlhks/ Perl and CGI - http://users.easystreet.com/ovid/cgi_course/ Personal blog - http://publius-ovidius.livejournal.com/ Tech blog - http://use.perl.org/~Ovid/journal/
Re: 99problems: 9, 11, 13
--- gabriele renzi <[EMAIL PROTECTED]> wrote: > Hi people, > > I implemented 13 from scratch because I didn't know it was already > solved, in this way > I think it's cleaner, shall I commit? I definitely think your solution is cleaner, but I'd be more inclined to see multiple solutions to problems rather than clearing out previous work. Not only does this follow the spirit of TIMTOWTDI, but it also allows the tests to cover a wider range of behavior. It's not really my call, though. Commit bits are there for a reason :) Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Re: 99 problems in Perl6: problem 28
--- gabriele renzi <[EMAIL PROTECTED]> wrote: > > Assuming the tests > > pass (I can't check this at work) and you have a commit bit, check > it > > in! > > they pass here, but I have no commit bit, it's ok if I do a darcs > push? > (I prefer it over svn) That's not my place to say. I can't give commit bits (and to be fair, it was possibly a bit cheeky of me to push this into Pugs, but no one objected on #perl6). > By the way, any comments on the code? :) I thought it looked quite nice, but given that I can't run it at work, I can't say more than that :) Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Re: 99 problems in Perl6: problem 28
Ah, nice to see someone else tackling the problems. Assuming the tests pass (I can't check this at work) and you have a commit bit, check it in! Cheers, Ovid --- gabriele renzi <[EMAIL PROTECTED]> wrote: > Hi everyone, and happy new year! > > I'm an almost complete newbie to Perl6 and I'm not that good at Perl5 > > either, but I thought playing with these problems could be fun, so I > tried to solve #28. > > My solution is attached, it seems to work, but I'd like to know from > people more expert than me if there could be a better solution. > > The first part seems reasonable, the second could probably be a > one-liner. > Probably I could replace usage of hash+for with gather/take and > nested > lists, but I don't think this makes the solution cleaner. > > Thanks in advance for any suggestion. > > use v6-alpha; > use Test; > plan 2; > > # P28 (**) Sorting a list of lists according to length of sublists > # > # a) We suppose that a list contains elements that are lists > themselves. The > # objective is to sort the elements of this list according to their > length. E.g. > # short lists first, longer lists later, or vice versa. > # > # Example: > # * (lsort '((a b c) (d e) (f g h) (d e) (i j k l) (m n) (o))) > # ((O) (D E) (D E) (M N) (A B C) (F G H) (I J K L)) > # > # b) Again, we suppose that a list contains elements that are lists > themselves. > # But this time the objective is to sort the elements of this list > according to > # their length frequency; i.e., in the default, where sorting is done > # ascendingly, lists with rare lengths are placed first, others with > a more > # frequent length come later. > # > # Example: > # * (lfsort '((a b c) (d e) (f g h) (d e) (i j k l) (m n) (o))) > # ((i j k l) (o) (a b c) (f g h) (d e) (d e) (m n)) > # > # Note that in the above example, the first two lists in the result > have length 4 > # and 1, both lengths appear just once. The third and forth list have > length 3 > # which appears twice (there are two list of this length). And > finally, the last > # three lists have length 2. This is the most frequent length. > # > # Arithmetic > > > my @input= [],[],[],[],[],[ n>],[]; > my @expected= [],[],[],[],[],[],[ k l>]; > > # we could use > # sort: {+$_} > # but pugs seem to not support this yet > > my @[EMAIL PROTECTED]: {+$^a <=> +$^b}; > is @expected, >@sorted, >"We should be able to sort a list of lists according to length of > sublists"; > > # the list is not the same as in the sample text, when two lists have > the > # same frequency of length the ordering is unspecified, so this > should be ok > > @expected= [],[],[],[],[],[],[ n>]; > > # group lists by length > > my %grouped; > for (@input) {%grouped{+$_}.push($_)} > > # now sort the values by frequency, again can't use > # sort: {+$_} > > @sorted= %grouped.values.sort: {+$^a <=> +$^b}; > is @expected,@sorted, "..or according to frequency of length of > sublists" > -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Junctions as arguments (Pugs bug)
Hi all, use v6-alpha; sub no_donut_for_you (Str $junction) { state $count = 0; $count++; return $count; } say no_donut_for_you( any( 'a' .. 'd' ) ); no_donut_for_you( any( 'a' .. 'd' ) ).say; That outputs something like the following on my system (Version: 6.2.13 (r14927)) any(VInt 1,VInt 2,VInt 3,VInt 4) any(VRef ) Taking out the final return or the state variable returns other strange outputs. Of course, that begs of the question of why I'm trying to cast a junction as a string, but also, note that I'm not even using the junction in the function. I discovered that by running the following, which not only ran 8 tests, but also spewed garbage all over my screen. use v6-alpha; use Test; plan 1; is 'b', any('a' .. 'h'), 'junctions should work'; I'll happily commit tests, but what is the expected behavior of my first code snippet? (I see now that other junction tests use ok() instead) Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
take: bug or feature?
A few days ago, Larry posted this on Perlmonks (http://perlmonks.org/?node_id=590147): sub group ([EMAIL PROTECTED] is copy) { gather { while @array { take [ # line 112 gather { my $h = shift @array; take $h; while @array and $h eq @array[0] { take shift @array; } } ]; } } } I added that to my "99 Problems" code because it worked just fine (I would swear it did. I'd be embarrassed if I am misremembering). Now I've upgraded Pugs and it fails with: Unexpected "[" expecting bare or pointy block construct, ":", identifier, operator or "}" at 99.pugs line 112, column 18 Line 112 is the first take. Did something break? If so, I'll add a test. Otherwise, what's wrong with this code? Also, I've been searching the docs for the exact syntax of 'gather/take' and I can't find it. Pointers would be great. Pugs Version: 6.2.13 (r14911) Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Unwanted scalar references
Hi all, Thanks for the answers to my previous questions. I do appreciate it. Today's stumper is this: sub decode([EMAIL PROTECTED]) returns Array { gather { for @list -> $elem { take $elem.isa(Array) ?? $elem[1] xx $elem[0] !! $elem; } } } decode( [3, "a"], "b", [1, "c"] ).perl.say; That prints: ("a", "a", "a", \"b", "c") How do I dereference "b"? Heck, why is it a reference in the first place? Actually, I have found one way to dereference is, but it seems wrong and buggy (using a prefix ++): sub decode([EMAIL PROTECTED]) returns Array { gather { for @list -> $elem { take $elem.isa(Array) ?? $elem[1] xx $elem[0] !! ++$elem; } } } decode( [3, "a"], "b", [1, "c"] ).perl.say; Oddly, using the postfix ++ gives me the error message I expect: *** Can't modify constant item: VRef at 99.pugs line 215, column 18-69 99.pugs line 215, column 18-69 Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
99 Problems in Perl6
Hi all, Want to learn Perl6 but you don't know what to write? I recently stumbled across 99 Lisp Problems (which was originally 99 Prolog Problems). It looked like fun, so I started answering those problems in Perl 6. This has shown me that I don't know Perl 6 nearly as well as I would like. The link to my sample Perl6 code and to the original 99 problems is at http://perlmonks.org/?node_id=590113 Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Strange error message with anon subroutine
In trying to compress a list, I wrote the following code: my $compress = do { my $previous; $compress = -> $x { if !defined $previous or $x ne $previous { $previous = $x; $x; } else { (); } }; } my @compressed = map $compress, ; @compressed.say; That's a bit more verbose than I intended, but that's partially because of this: my $compress = do { my $previous; $compress = -> $x { if !defined $previous or $x ne $previous { $previous = $x; return $x; } else { return (); } }; }; As soon as I put the return statements in an anonymous subroutine, I get this error message: *** Cannot use this control structure outside a 'routine' structure at 99.pugs line 103, column 13-22 Take out the returns, and it works fine. Can someone tell me what I'm missing? Is this a bug. Also, I noticed I accidentally left off the final semi-colon on the do block. It ran anyway and that surprised me. Cleaner ways of writing that code are welcome, too. Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Introspection and list question
Hi all, A couple of quick things. First, how do I do introspection in Pugs? CPAN's Perl6::Bible hasn't been updated in a while, but the various ways to get a list of methods (from http://search.cpan.org/dist/Perl6-Bible/lib/Perl6/Bible/S12.pod#Introspection or http://tinyurl.com/yxukar) don't appear to work. They all throw syntax errors or "No compatible subroutine" errors. Also, I'm having trouble with problem 7 in http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html or http://tinyurl.com/tt9e7. Basically, it's flattening nested lists and I'm embarrassed to admit that I can't figure this out in Perl6. Thoughts? I've been reading synopses and grepping through Pugs, but to no avail. Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Re: Error running Pugs tests
--- Gaal Yahas <[EMAIL PROTECTED]> wrote: > On Tue, Dec 12, 2006 at 02:14:42AM -0800, Ovid wrote: > > pugs $ pugs t/general/basic.t > > pugs: user error (*** > > Unexpected "Str" > > expecting "\\", ":", "*", parameter name or ")" > > at /usr/local/lib/perl6/Test.pm line 34, column 21 > > t/general/basic.t line 1, column 1) > > You have an old version of Test.pm (and likely, other modules too) > from > an earlier 'make install'. Better wipe out your /usr/local/lib/perl6 > and any other traces. Thanks. That fixed it. Now for some fun: http://www.ic.unicamp.br/~meidanis/courses/mc336/2006s2/funcional/L-99_Ninety-Nine_Lisp_Problems.html or http://tinyurl.com/tt9e7 Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Error running Pugs tests
Hi all, Just built GHC 6.6 from source (oh joy!) and upgraded to Pugs Version: 6.2.13 (r14881). After building it I did a "make install" and in the pugs directory, I tried this: pugs $ pugs t/general/basic.t pugs: user error (*** Unexpected "Str" expecting "\\", ":", "*", parameter name or ")" at /usr/local/lib/perl6/Test.pm line 34, column 21 t/general/basic.t line 1, column 1) However, it works when I do this: pugs $ pugs -Iblib6/lib t/general/basic.t 1..15 ok 1 - Welcome to Pugs! ok 2 - undef ok 3 - unless ok 4 - list assignment 1 ok 5 - list assignment 2 not ok 6 - my() returns LHS # TODO # Failed (TODO) test (t/general/basic.t line 26, column 1-60) # Actual: undef ok 7 - if without parens ok 8 - for without parens ok 9 - while ok 10 - last ok 11 - next ok 12 - 12.eval ok 13 - ?? !! ok 14 - { my $_ = 1; $_ } ok 15 - \# We've got fun and games! I don't have pugs here at work (or time for it, really), but I was wondering why I appear to be getting a syntax error if I don't include blib6/lib? That strikes me as very strange. Can anyone else reproduce this? If not, I can dig into my system and see what's up. Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Re: Runtime Role Issues
--- Audrey Tang <[EMAIL PROTECTED]> wrote: > > I always thought when a role is applied to a class at runtime you > > get a new (anonymous) subclass. The original class isn't affected. > > Right, that's what usually happens with: > > my Dog $fido .= new; > $fido does Catlike; Am I missing something here? That's applying a role to an instance of a class, not the class itself, and thus *should* create a new anonymous class. > To forcefully add a role to a class at a distance during runtime, use > a class object call (see Moose::Meta::Class for more about these > APIs): > > ^Dog.add_role(^Catlike); That's more of what I was thinking, but where is this documented? I can't find it in http://dev.perl.org/perl6/doc/design/syn/S12.html. I see it in the Moose docs, but is this in Perl 6? I thought it was. Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Runtime Role Issues
Hi all, In doing a bit of work with traits (roles) in Perl 5 (http://perlmonks.org/?node_id=577477), I've realized some edge cases which could be problematic. First, when a role is applied to a class at runtime, a instance of that class in another scope may specifically *not* want that role. Is there a way of restricting a role to a particular lexical scope short of merely applying that role to instances instead of classes? Second, how can I remove roles from classes? I've create some code which adds an "is_selected" method to some classes but when I'm done, I'd like top easily remove that role. How do I do that? Seems closely related to my first question, but it's still a distinct issue, I think. Third, http://dev.perl.org/perl6/doc/design/syn/S12.html says: You can also mixin a precomposed set of roles: $fido does Sentry | Tricks | TailChasing | Scratch; Should that be the following? $fido does Sentry & Tricks & TailChasing & Scratch; Cheers, Ovid -- Buy the book -- http://www.oreilly.com/catalog/perlhks/ Perl and CGI -- http://users.easystreet.com/ovid/cgi_course/
Re: $1,000 prize for Perl 6 Wiki written in Perl 6
Hi Conrad, I run the grant committee for the Perl Foundation and I sit on the steering committee, so I suppose I can discuss your proposal (there are some other TPF folk here, too, so that's why this is a public email). Also, the following stuff is just off the top of my head and is in no way official. For TPF to handle something like this, we'd have to have some agreement on what the specs are, who would judge whether or not a Wiki met the specs and what to do if there were timing concerns (if we get one Wiki before another even the the later one was sent first, who wins?) Also, though I hate to be a spoilsport and bring this up, I'm really not sure what legal issues might be involved with running a contest, either. Would that be considered a form of gambling and possibly be illegal? I don't think so, but I'm not sure. In any event, if you can come up with a solid set of contest rules, TPF can consider whether or not we can officially run the contest. It sounds like a nice idea, I just don't know what's involved. Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/ - Original Message From: Conrad Schneiker <[EMAIL PROTECTED]> To: perl6-users@perl.org Sent: Thursday, June 1, 2006 12:00:51 AM Subject: RE: $1,000 prize for Perl 6 Wiki written in Perl 6 Does anyone out there have any phone numbers for key contacts at The Perl Foundation that you could send to me off-list? So far, I've not heard back from anyone there. TIA. Best regards, Conrad Schneiker http://perl.net.au/wiki/Perl_6_Users_FAQ (Moved from AthenaLab to Perl 6 Wiki.) www.AthenaLab.com (Nano-electron-beam and micro-neutron-beam technology.) From: Conrad Schneiker [mailto:[EMAIL PROTECTED] Sent: Saturday, May 27, 2006 2:35 PM > From: Conrad Schneiker [mailto:[EMAIL PROTECTED] > Sent: Saturday, May 27, 2006 2:35 PM > To: 'perl6-users@perl.org' > Cc: '[EMAIL PROTECTED]'; 'Nathan Eady'; '[EMAIL PROTECTED]'; > '[EMAIL PROTECTED]' > Subject: $1,000 prize for Perl 6 Wiki written in Perl 6 > > OK, Im sold on a Perl 6 Wiki written in Perl 6aka the (Perl 6) > **2 Wiki. > > However, I want it now! > > So Im offering to post a $1,000 prize (The AthenaLab The 1st > Extreme Leverage Prize for Perl 6), to be awarded to the person > that delivers the first (Perl 6)**2 Wiki that meets some moderate > specifications. > > Heres what I currently have in mind. > > The prize money would be held in escrow by The Perl Foundation > (*IF* they are willing to handle this). The Perl Foundation would > decide when a prize claimant had adequately realized the > specifications. (Entries must be announced on perl.perl6.users. > To facilitate collaboration, the designated winner may request > that the prize be split up and distributed among up-to-10 cohorts > or charities, with names and amounts to be publicly specified in > advance on perl.perl6.users.) > > The specifications for the (Perl 6)**2 Wiki would be determined > (and posted to perl.perl6.users) by @Larry (*IF* they are willing > to handle this). One of the reasons for wanting @Larry to handle > the specification for this prize is my presumption that they best > know what is presently (or soon will be) reasonable to > implement. Perl 6 means Pugs + Parrot for purposes of this prize. > (However, if @Larry recommends s/Parrot/Perl5/ for now, thats > also OK with me.) Practically usable minimalism and the ( > http://www.perldesignpatterns.com/?TinyWiki) approach of starting > with the simplest (working) thing possible is fine. The aim is > not to impress with world with the first implementation, but > rather to initiate a self-sustaining chain reaction of > improvement that will much later (a year from now) impress the > world with the cumulative rate of progress. > > The license must be whatever the prevailing license was for the > Pugs (Perl 6 core) svn source tree is at the time the prize is > claimed. The source code would be added to the examples or > cookbook section of the Pugs source tree. (Details to be > determined by @Larry.) > > The contestant (or contestants) are encouraged to seek help and > feedback on public forums. Just be up-front about it. Taking the > initiative needed to deliver the result is what is being > rewarded, not doing it on your own. > > The (Perl 6)**2 Wiki must be installed and demonstrated on > Feather, Juerds Perl 6 development server (*IF* this is OK with > him, and if he can arrange for www.perl6.nl to go to the new > Wiki, *UNLESS* the Perl Foundation wants to host the main Wiki, >
Re: Minimum modules for Production?
- Original Message > From: David Cantrell <[EMAIL PROTECTED]> > > Too many people have said "it'll be over by christmas" for me to have > any confidence in such prognostications, but ... I can't say I blame you. I'm just going by my gut, what I've seen before and what some birds have sung in my ear. My opinion on this matter, though, is strictly my opinion and is in no way official. > I doubt a HTML parser is that important. Something like Storable and > GDBM_File are though. When Andy mentioned the Phalanx project, I had the same reaction to some of the modules in that project. However, as has been pointed out regarding MS Word, most users only use a very tiny subset of its functionality. The problem is that the users are using different subsets. I've done huge amounts of HTML parsing and can't recall having used GDBM_File. Perl6 without a robust HTML parser would be quite limited for me, though I'm sure one will be ready soon. Cheers, Ovid
Minimum modules for Production?
Since it looks like we're really going to have Perl6 within a year or so, what are the "must have" modules folks will want before they can consider using Perl6 in production? Right off the bat, I see a need for the following: DBI (I hear Tim Bunce is looking at this) Template Toolkit (I've heard rumors that Andy Wardley is considering this, but I'm not sure) DateTime CGI Some object-relational mapper mod_perl6 or some equivalent An HTML parser Various testing modules Some of those are already in Pugs, or are at least started. Much of the rest can be hacked up on the fly. Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
Re: CGI on 6
- Original Message From: Michael Mathews <[EMAIL PROTECTED]> On 30/05/06, Ovid <[EMAIL PROTECTED]> wrote: > > I assume this is just an attempt to learn Perl6 and not to write a serious > > CGI parser? > > Assuming it's the former and not the latter, I don't really have much to > > comment on, > > though there are a few things I would change. > > How mysterious. Short of begging, what would it take to get you to > reveal the "few things you would change"? Do I need to pony up another > 1000 Pesos (which will not actually be honoured)? Now that I read what I wrote, I guess that might have sounded a bit annoying for me to mention that I would change things but then not mention what I would change. Much of the changes would be stylistic in nature, but not all (I'm running this against Pugs and assuming it's correct). Here's my take on it: #!/usr/bin/pugs print "content-type: text/html\n\n"; my %q; for %ENV.split('&') -> $nv { my ($n, $v) = $nv.split('='); decode($n); decode($v); %q{$n} = [] unless %q.exists($n); # %q{$n} //= []; # first try, but I don't think it's correct %q{$n}.push($v); } for %q.kv -> $key, $value { say "$key => $value.join(', ') "; } sub decode($input is rw) { $input ~~ s:Perl5:g/\+/ /; $input ~~ s:Perl5:g/%(..)/{chr(:16["0x$0"])}/; } This ignores the ";" query string separator, POST parameters and a number of other things, but since this isn't an attempt to get CGI correct but instead is an attempt to better understand Perl6, that's OK. Whether or not my code is a significant improvement over your's remains to be seen :) I also tried to do this: my ($n, $v) = $nv.split('=').map(decode($_)); That and a number of other variants all failed miserably with errors similar to: Can't modify constant item: VStr ... Cheers, Ovid
Re: CGI on 6
Michael, I assume this is just an attempt to learn Perl6 and not to write a serious CGI parser? Assuming it's the former and not the latter, I don't really have much to comment on, though there are a few things I would change. Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
Re: CGI on 6
- Original Message > From: Conrad Schneiker <[EMAIL PROTECTED]> > > More code here (and in subdirectories): > https://svn.perl.org/perl6/pugs/trunk/ext/CGI I'm on a friend's computer so I can't check that, but I seem to recall that that interface was borrowed directly from Perl5's CGI.pm. This might be an opportunity to consider taking care of any nits we might have with that module as the stuff which is in ext/ might get sent to the CPAN. In fact, anyone who has gripes about the interface of various Perl5 modules might want to consider this opportunity ... > Looks like this was reserved for your personal use. :-) > http://svn.perl.org/perl6/pugs/trunk/examples/cookbook/19cgi-programming/ The cookbook project bogged down terribly after some initial great momentum. If anyone wants to write some recipes, I can't speak for Audrey, but she was quite willing to hand out committer bits and I suspect she'd be happy to have more of the cookbook fleshed out. We need it very badly! Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
Re: Introductions; P6 wiki
On a related note, if anyone does want to build a P6 Wiki, you might consider building it on top of WWW::Kontent (http://search.cpan.org/dist/WWW-Kontent/), a Perl6 CMS (Content Management System) that BrentDax wrote. Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/ - Original Message From: Paul Fenwick <[EMAIL PROTECTED]> To: perl6-users@perl.org Sent: Saturday, May 27, 2006 4:46:23 AM Subject: Introductions; P6 wiki G'day Everyone, I'm very glad to have finally subscribed to the P6 users list after a couple of weeks of travel and intermittent network access, and so I apologise that this message may not be properly threaded. This is both a note of introduction and a few words on the recent discussion about the P6 wiki ideas. For those of you whom I have not yet had the pleasure of meeting, I run Perl Training Australia ( http://perltraining.com.au/ ), am the secretary of Melbourne Perl Mongers, and speak whenever I get the chance at many of the Australian conferences and user-groups. I'm regularly asked about Perl 6, and I often show it off to enthusiastic students during lunch breaks. I'm also one of the admins of PerlNet ( http://perl.net.au/ ), which brings us nicely to the talk of P6 wikis. I love the idea of the P6 wiki being written in P6, I think it's a fantastic idea. However I'm also aware that there are no P6 wiki implementations yet, and it will probably take some time to get one running. So can we have our cake and eat it too? I believe the answer is yes. I can't see any problems with using an existing wiki, be it Feather, or PerlNet, or any other wiki, with the intention to migrate the content to a P6-in-P6 wiki when such becomes available. The main thing to be careful of is ensuring that people are aware of the migration plans, and that there are no license problems. The last thing we want are social or legal barriers to migrating content. I do agree with Jured's sentiments that requiring the P6 wiki to support the kitchen sink will make migration more difficult, and so that simplicity in mark-up for any interim wiki is a good thing. In the meantime, if anyone does want to use perl.net.au for any P6 (or Perl in general), you should feel very encouraged to do so, even if it's with the intention of migrating that content in the future. Cheerio, Paul -- Paul Fenwick <[EMAIL PROTECTED]> | http://perltraining.com.au/ Director of Training | Ph: +61 3 9354 6001 Perl Training Australia| Fax: +61 3 9354 2681
Re: Logic Programming for Perl6 (Was Re: 3 Good Reasons... (typo alert!))
- Original Message From: David Romano <[EMAIL PROTECTED]> > > duplicate results and this is almost always wrong. (See > > http://use.perl.org/~Ovid/journal/28378 > > for an SQL example of this problem). > I re-read your journal entry and comments (I had read it back when you > first had posted it), and I'm curious about what obstacles that you > think need to be overcome for Perl6 to support logic programming. If anyone wants to know what the heck this is about, you can read http://search.cpan.org/dist/AI-Prolog/lib/AI/Prolog/Article.pod That's an article I originally had published in The Perl Review (http://www.theperlreview.com/) and it explains the basics of logic programming and how to do it in Perl5. It also explains the append/3 predicate, something I mention below. The first hurdle would be the syntax. The programmer just looking at the code would need to know when one section of code represents a snippet of logic programming. Is the following a function call or a Prolog fact? loves( 'foo', 'bar' ); How would one assert facts and rules in Perl6? How would one know that a variable is a logic variable and not a normal one? Assignment to a logic variable which is still subject to rebinding could break code. On the other hand, using normal variables for logic variables could let us use objects for them and I think this might get us contraint programming (long story). There's also the question of non-logical behavior in logic programming. What happens if you try to use math in Perl6 logic programming? Generally speaking, math is "non-logical" in the sense that it's used in Prolog (see the aforementioned article). Opening and reading from a file is also non-logical (you can't backtrack over it). How are those issues to be handled? My biggest concern, though, is a rule like the following: customer_cities(City) :- 700 <= credit_rating(Customer), customer(Customer, City). That's logically equivalent to the SQL I posted in a previous email and, like that SQL, will very likely return duplicates. Prolog students are constantly faced wtih the "how do I get rid of duplicates?" problem. This results in inefficient queries and a lot of time spent culling the duplicate answers when the person just wants to know the list of cities which meets their requirements. Perl6 grammars may be able to assist with this, but grammars (as far as I can tell) are still based around strings and not data structures. Admittedly, Prolog is essentially a fancy string rewriting system, but it's not clear how the grammars would be applied to this problem. For anyone familiar with logic programming and the append/3 predicate, here's one way of representing it in Perl5: use re 'eval'; my $string = "abc"; my $length = length $string; my $regex = qr/(\G[$string]{0,$length}(?{print "# [$&][$'][$string]\n"}))/ x 2; $string =~ $regex; Can you say "yuck"? However, that only represents a limited subset of append/3's functionality and trying to generalize it would be a very difficult task. One approach might be to write a wrapper around http://www.perlmonks.org/?node_id=318350. That's an approach I found to leverage Perl5's regex engine for logic programming, but I discovered that Perl5's regexen aren't re-entrant, killing that project. Perl6 rules might be perfect for this. In short, there are lots of questions which would need to be answered to get logic programming done correctly in Perl6. I'm quite happy that @Larry decided not to answer those questions since things would have been delayed. We can hack in logic programming later. Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
Re: 3 Good Reasons... (typo alert!)
Sheesh. I type things too fast and then I see the horrifying typos I've made (blush) - Original Message From: Ovid <[EMAIL PROTECTED]> > do things that is hard to do in other languages. "do things that *are* hard to do in other languages" > Perl6 not only fixes a lot of that cruft but also adds new, powerful features > which > makes programmers more productive and thus can churn out apps quicker. "which make" > The can alleviate many bugs "This can alleviate many bugs" > And to multiple all items in an array by some value? "multiply" OK, I'll stop now even though there's more. Wow. What a terrible mess. As an aside for those who, like me, wanted to see support for logic programming: the only significant disappoinment I have with Perl6 is also, oddly enough, accompanied by a sigh of relief. Perl6 will easily support imperative, functional and OO syntax. But what about logic programming? Perl6 rules might help, but there will be no support for things that Prolog and Mercury do naturally. The "sigh of relief" stems from my realization that logic programming in Perl6 would probably be implemented incorrectly because the easiest way to implement it is usually wrong, though this can be very tough to see at first. It's my understanding that logic programming wasn't incorporated due to the desire to not delay the initial release of Perl6 (I could be wrong). However, after having done a fair amount of work with logic programming, I realize that one of the greatest implementation mistakes with it is that results tend to be bags and not sets (SQL shares this problem). Thus, when one naturally wants all of the answers to a query, one often gets duplicate results and this is almost always wrong. (See http://use.perl.org/~Ovid/journal/28378 for an SQL example of this problem). Cheers, Ovid
Re: 3 Good Reasons...
ly, I want to thank Larry, Damian, Luke, chromatic, Allison, Audrey and many more for their fine work in designing and implementing Perl6 (gush, gush, gush). I was leaning away from Perl5 due to its limitations, but now I'm here to stay. I am supremely confident that Perl6 will be a hugely popular language simply based on its merits, not marketing. Cheers, Ovid
Re: Simple Print/Say Question
First off, thanks to Aristotle for clearing some of my thinking. - Original Message From: A. Pagaltzis <[EMAIL PROTECTED]> >my %buckets = ( >w => { >count => 4, >scale => 10.5, > }, >); > >for %buckets.values -> $arg_for { >$arg_for = [ ( 0 .. $arg_for ) »*« $arg_for ]; >} In my version of Pugs (6.2.11 (r10390)), that fails for two reasons, both of which I suspect are bugs. First, unless the hash elements have an "array => []" pair, I seem to get the following error: *** Can't modify constant item: VUndef at bucket.p6 line 21, column 5-73 Line 21 in my code is the assignment to $arg_for. However, even putting that back in results in the exact same error, so I had to change the line to: $arg_for.push((0 .. $arg_for) >>*<< $arg_for ); Now you might be thinking that I simply needed change the $arg_for assignment to a push and not included the "array => []" pair, but as it turns out, I need the pair *and* the push lest I get the VUndef error. for %buckets.kv -> $i, $w { Is .kv supposed to work there? You're accessing an array, not a hash. > I assume all those temporaries that I cleaned out were there for > speed, in which case this will run slower, but they were too > unsightly to keep around. Yeah, that's why they were there. However, the ($x, $y, $z).sum > $target is a much more useful performance hack, so you could get rid of the temporaries. Cheers, Ovid
Re: Simple Print/Say Question
- Original Message From: Jonathan Scott Duff <[EMAIL PROTECTED]> > pushes an array reference onto @results (rather than things that are > int). If you're going to type @results, maybe it needs to be: > > my @results is Array of Array of int; > > or maybe > > my Array of int @results; Yes, I believe you're right. Nice catch! Too bad that generates the following error: *** unexpected "o" expecting comment, variable name or "(" at bucket.p6 line 24, column 10 As I recall, Pugs only uses the "int" and "array" stuff as comments right now, though I could be mistaken. Cheers, Ovid
Re: Simple Print/Say Question
- Original Message > From: Larry Wall <[EMAIL PROTECTED]> > > You should not need "my" on the right side of a ->. Also, you should > be able to write $arg_for for constant subscripts. Thanks! The revised script is below for those who are interested. Cheers, Ovid - my %buckets = ( 'w' => { 'count' => 4, 'scale' => 10.5, 'array' => [], }, 'x' => { 'count' => 6, 'scale' => 7, 'array' => [], }, 'y' => { 'count' => 12, 'scale' => 3, 'array' => [], }, 'z' => { 'count' => 18, 'scale' => 2, 'array' => [], }, ); for %buckets.values -> $arg_for { for 0 .. $arg_for -> $index { $arg_for.push($index * $arg_for); } } my int @results; my int $target = 35; my $w_bucket = %buckets; for 0 .. $w_bucket -> $i { say "To 4: $i"; my $w = $w_bucket[$i]; last if $w > $target; my $x_bucket = %buckets; for 0 .. $x_bucket -> $j { say " To 6: $j"; my $x = $x_bucket[$j]; last if ($w, $x).sum > $target; my $y_bucket = %buckets; for 0 .. $y_bucket -> $k { my $y = $y_bucket[$k]; last if ($w, $x, $y).sum > $target; my $z_bucket = %buckets; for 0 .. $z_bucket -> $l { my $z = $z_bucket[$l]; if( $target == ($w, $x, $y, $z).sum ) { @results.push( [$i, $j, $k, $l] ); } } } } } my $counter = 0; for @results -> $result { say "$counter: " ~ $result.join(" | "); $counter++; }
Re: Simple Print/Say Question
Er, and the first loop is better written as this: for %buckets.values -> my $arg_for { for 0 .. $arg_for{'count'} -> $index { $arg_for{'array'}.push($index * $arg_for{'scale'}); } } Instead of: for %buckets.kv -> my $bucket, $arg_for { for 0 .. $arg_for{'count'} -> $index { $arg_for{'array'}.push($index * $arg_for{'scale'}); } } Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/
Re: Simple Print/Say Question
Hi Chris, I hope you don't mind. With the idea of getting back into Perl6, I've taken the liberty of rewriting your code to clean it up a bit (somewhat successfully), and make it more "perl6ish" (somewhat unsuccessfully). The only significant issue I have with my version is the terribly nested loop which I'm sure could be cleaned up some more. Also, because Pugs is so slow, I've included some performance hacks in it. It originally was taking about 4 minutes to run on my computer. It now takes about 50 seconds. If anyone can offer a better/cleaner version, I'd love to see it. Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/-- my %buckets = ( 'w' => { 'count' => 4, 'scale' => 10.5, 'array' => [], }, 'x' => { 'count' => 6, 'scale' => 7, 'array' => [], }, 'y' => { 'count' => 12, 'scale' => 3, 'array' => [], }, 'z' => { 'count' => 18, 'scale' => 2, 'array' => [], }, ); for %buckets.kv -> my $bucket, $arg_for { for 0 .. $arg_for{'count'} -> $index { $arg_for{'array'}.push($index * $arg_for{'scale'}); } } my int @results; my int $target = 35; my $w_bucket = %buckets{'w'}; for 0 .. $w_bucket{'count'} -> my $i { say "To 4: $i"; my $w = $w_bucket{'array'}[$i]; last if $w > $target; my $x_bucket = %buckets{'x'}; for 0 .. $x_bucket{'count'} -> my $j { say " To 6: $j"; my $x = $x_bucket{'array'}[$j]; last if ($w, $x).sum > $target; my $y_bucket = %buckets{'y'}; for 0 .. $y_bucket{'count'} -> my $k { my $y = $y_bucket{'array'}[$k]; last if ($w, $x, $y).sum > $target; my $z_bucket = %buckets{'z'}; for 0 .. $z_bucket{'count'} -> my $l { my $z = $z_bucket{'array'}[$l]; if( $target == ($w, $x, $y, $z).sum ) { @results.push( [$i, $j, $k, $l] ); } } } } } my $counter = 0; for @results -> my $result { say "$counter: " ~ $result.join(" | "); $counter++; }
Re: Simple Print/Say Question
This seems to work for me: pugs -e 'say (1,2,3).join("|")' 1|2|3 Or even: pugs -e '(1,2,3).join("|").say' 1|2|3 Cheers, Ovid -- If this message is a response to a question on a mailing list, please send follow up questions to the list. Web Programming with Perl -- http://users.easystreet.com/ovid/cgi_course/ - Original Message From: Fagyal Csongor <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] Cc: perl6-users@perl.org Sent: Tuesday, May 23, 2006 12:11:07 PM Subject: Re: Simple Print/Say Question Chris, Strange. I have just tried this using an old version (6.2.3) of Pugs: my (@array) = 1,2,3; print @array[0] ~ "|" ~ @array[1] ~ "|" ~ @array[2] ~ "\n"; It prints 1|2|3 on my terminal. Gabor's join-ed version also works. - Fagzal > Oops. That last . is a typo on my part. Sorry about that! It should > read, which it does in my code: > > print @array[0] ~ "|" ~ @array[1] ~ "|" ~ @array[2] ~ "\n"; > > However, your say join technique does not work. I will keep on it but > for now I am off to dinner! > > Thanks!, > Chris > > On 5/23/06, Gabor Szabo <[EMAIL PROTECTED]> wrote: >> On 5/23/06, Chris Yocum <[EMAIL PROTECTED]> wrote: >> > >> > 1|2|3 >> > >> > I would say something like: >> > >> > print $array[0] . "|" . $array[1] . "|" . $array[2] . "\n"; >> > >> > not the best way but it works. >> > >> > In Perl6 if say something like this: >> > >> > print @array[0] ~ "|" ~ @array[1] ~ "|" ~ @array[2] . "\n"; >> > >> > I get >> > >> > 1 2 3 | | | >> > >> > My question is: why is it doing that or, more to the point, what am >> I doing wrong? >> > >> >> I am not sure, maybe the . before "\n" cause the problem but why not >> try this one: >> >> my @array = (1, 2, 3); >> say join "|", @array; >> >> Gabor