Re: [perl #61088] [PATCH] show result of expressions in HLLCompiler based interactive REPLs
On Mon, Sep 21, 2009 at 8:26 AM, Will Coleda via RT parrotbug-follo...@parrotcode.org wrote: Sorry for the delay - this patch had stalled waiting for review due to a ticketing system changeover, and in the meantime, no longer applies cleanly against parrot HEAD. Can you rebase this patch and resubmit it to https://trac.parrot.org/ ? Hopefully we can provide better turnaround next time. done, I still think this can be made better (and I had a better patch in the making, but then reality occured) by having read() eval() print() and loop() subs calling each othjer and being overrideable, but I have no time to complete the patch now. All tests still appear to pass but there are no new one for this featurette, sorry. Thanks again! glad to be helpful :)
[perl #61088] [PATCH] show result of expressions in HLLCompiler based interactive REPLs
# New Ticket Created by gabriele renzi # Please include the string: [perl #61088] # in the subject line of all future correspondence about this issue. # URL: http://rt.perl.org/rt3/Ticket/Display.html?id=61088 the current HLLCompiler infrastructure seems to be an incomplete REPL, since it only does Read-Eval-Loop. This patch adds a simple Print step and a new attribute commandline_result_prompt similar to commandline_prompt, defaulting to = . It also changes the default commandline_prompt toto make the two vertically aligned. A better approach may be splitting the functionality of the interactive() method into calls to multiple overrideable methods (read, print) to allow further customization from users of the class. the difference is easy to show, with rakudo: 1 = 1 1+3 = 4 say hello hello = 1 1.WHAT = Int 1.HOW = get_string() not implemented in class 'P6metaclass' current instr.: 'parrot;PCT;HLLCompiler;interactive' pc 1072 (src/PCT/HLLCompiler.pir:592) called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1470 (src/PCT/HLLCompiler.pir:793) called from Sub 'parrot;Perl6;Compiler;main' pc 16749 (perl6.pir:166) vs 1 1+3 say hello hello 1.WHAT 1.HOW I did not install an exception handler for missing failure in the internal say() call cause it feels this should not happen anyway. OTOH other exceptions are correctly handled as usual say miao Could not find non-existent sub miao say $miao Scope not found for PAST::Var '$miao' Furthermore, notice that if the result of the operation is null nothing is printed (python-like behaviour) so for example the default language shell will have say 1; 1 say hello; hello All parrot and rakudo tests seem to pass, which means that probably there are no tests for this functionality at all. The patch respects the previous behaviour of special casing the PIR target so that it does not print anything else. repl3.patch Description: Binary data
[perl #61086] [PATCH] mk_language_shell script generates wrong
# New Ticket Created by gabriele renzi # Please include the string: [perl #61086] # in the subject line of all future correspondence about this issue. # URL: http://rt.perl.org/rt3/Ticket/Display.html?id=61086 the default grammar for a newly generated language shell contains the following lines: rule integer { \d+ {*} } rule quote { [ \' string_literal: '\'' \' | \ string_literal: '' \ ] {*} } since these are defined as rule they skip whitespace, so the second declaration actually forces parsing of literals like into The attached patch modifies mk_language_shell to generate a grammar that declares these as tokens and adds an additional test to the default t/00-sanity.t generated for a new lanaguage shell that takes this into account. All parrot tests still pass, cause there is nothing testing mk_language_shell output, AFAICT. The documentation in languages/squaak/doc may be updated to reflect the change but it seems the only direct reference is languages/squaak/doc/tutorial_episode_3.pod:Rename the rule Cinteger as Cinteger_constant, and Cquote... whereas it may say token but I guess it's pretty fine even like this. Parrot svn at revision 33548. token_for_literal.patch Description: Binary data
[perl #61020] [BUG] double free or corruption when calling non-existent sub from the perl6 executable
# New Ticket Created by gabriele renzi # Please include the string: [perl #61020] # in the subject line of all future correspondence about this issue. # URL: http://rt.perl.org/rt3/Ticket/Display.html?id=61020 This happens wither with a line like 1.size or simply size The error I get for the former [EMAIL PROTECTED]:~/parrot/languages/perl6$ ./perl6 p2.pl Method 'size' not found for invocant of class 'Int' current instr.: '_block11' pc 23 (EVAL_11:15) called from Sub 'parrot;PCT;HLLCompiler;eval' pc 892 (src/PCT/HLLCompiler.pir:508) called from Sub 'parrot;PCT;HLLCompiler;evalfiles' pc 1227 (src/PCT/HLLCompiler.pir:674) called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1403 (src/PCT/HLLCompiler.pir:762) called from Sub 'parrot;Perl6;Compiler;main' pc 16408 (perl6.pir:168) *** glibc detected *** ./perl6: double free or corruption (!prev): 0x08356858 *** === Backtrace: = /lib/tls/i686/cmov/libc.so.6[0xb781da85] /lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb78214f0] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(mem_sys_free+0x23)[0xb7b70c83] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b70daf] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7b947] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_exit+0x70)[0xb7b670b0] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b664c9] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_ex_throw_from_op+0x24)[0xb7b66584] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_ex_throw_from_op_args+0x54)[0xb7b66944] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_callmethodcc_p_sc+0x15d)[0xb7b17b3d] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7bacc9c] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7d749] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7e023] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7e310] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_runops_fromc_args+0x4c)[0xb7b7e45c] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_ex_throw_from_c+0x1a7)[0xb7b668d7] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b6699d] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7ba082a] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7ba0894] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7d94b6a] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_Class_init_pmc+0x228)[0xb7d965f8] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(pmc_new_init+0xb1)[0xb7bac111] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_newclass_p_p+0x58)[0xb7b18d88] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7bacc9c] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7d749] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7e023] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7e310] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_runops_fromc_args+0x4c)[0xb7b7e45c] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_ex_throw_from_c+0x1a7)[0xb7b668d7] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b6699d] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7ba082a] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7ba0894] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7d94b6a] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_Class_init_pmc+0x228)[0xb7d965f8] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(pmc_new_init+0xb1)[0xb7bac111] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_newclass_p_p+0x58)[0xb7b18d88] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7bacc9c] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7d749] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7e023] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7e310] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_runops_fromc_args+0x4c)[0xb7b7e45c] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_ex_throw_from_c+0x1a7)[0xb7b668d7] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b6699d] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7ba082a] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7ba0894] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7d94b6a] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_Class_init_pmc+0x228)[0xb7d965f8] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(pmc_new_init+0xb1)[0xb7bac111] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_newclass_p_p+0x58)[0xb7b18d88] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7bacc9c] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7d749] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7e023] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b7e310] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_runops_fromc_args+0x4c)[0xb7b7e45c] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_ex_throw_from_c+0x1a7)[0xb7b668d7] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7b6699d] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7ba082a] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7ba0894] /home/rff/parrot/blib/lib/libparrot.so.0.8.1[0xb7d94b6a] /home/rff/parrot/blib/lib/libparrot.so.0.8.1(Parrot_Class_init_pmc+0x228)[0xb7d965f8] /home/rff/parrot/blib/lib/libparrot.so.0.8.1
[perl #60976] [PATCH] rakudo fails to build AST for subset declaration with regex literal
# New Ticket Created by gabriele renzi # Please include the string: [perl #60976] # in the subject line of all future correspondence about this issue. # URL: http://rt.perl.org/rt3/Ticket/Display.html?id=60976 The bug is visibile with the following line subset GenderStr of Str where /^[m|f]$/ ; for what I can tell the problem is due to the code to manage type_declarator that only checks if a EXPR is a PAST::Block. A regex is recognized as a block but it lacks some of the structure so I get this error: .Method 'push' not found for invocant of class 'Perl6;Grammar' current instr.: 'parrot;Perl6;Grammar;Actions;_block5542' pc 141736 (src/gen_actions.pir:15745) called from Sub 'parrot;Perl6;Grammar;Actions;_block5532' pc 141655 (src/gen_actions.pir:15715) called from Sub 'parrot;Perl6;Grammar;Actions;type_declarator' pc 141016 (src/gen_actions.pir:15507) called from Sub 'parrot;Perl6;Grammar;type_declarator' pc 56741 (src/gen_grammar.pir:15033) called from Sub 'parrot;Perl6;Grammar;noun' pc 66124 (src/gen_grammar.pir:18653) called from Sub 'parrot;Perl6;Grammar;expect_term' pc 60939 (src/gen_grammar.pir:16680) called from Sub 'parrot;PGE;OPTable;parse' pc 1979 (compilers/pge/PGE/OPTable.pir:554) called from Sub 'parrot;Perl6;Grammar;statement' pc 27186 (src/gen_grammar.pir:3693) called from Sub 'parrot;Perl6;Grammar;statementlist' pc 24938 (src/gen_grammar.pir:2818) called from Sub 'parrot;Perl6;Grammar;statement_block' pc 22476 (src/gen_grammar.pir:1847) called from Sub 'parrot;Perl6;Grammar;TOP' pc 18370 (src/gen_grammar.pir:229) called from Sub 'parrot;PCT;HLLCompiler;parse' pc 640 (src/PCT/HLLCompiler.pir:390) called from Sub 'parrot;PCT;HLLCompiler;compile' pc 434 (src/PCT/HLLCompiler.pir:303) called from Sub 'parrot;PCT;HLLCompiler;eval' pc 868 (src/PCT/HLLCompiler.pir:502) called from Sub 'parrot;PCT;HLLCompiler;evalfiles' pc 1233 (src/PCT/HLLCompiler.pir:676) called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1412 (src/PCT/HLLCompiler.pir:765) called from Sub 'parrot;Perl6;Compiler;main' pc 16408 (perl6.pir:168) Wich seem related to line 3025: $past[0].push($param); where possibly $past[0] is empty. A simple solution is to check that the value passed actually is a regex by verifying the .compiler attribute, and then manage it as just another literal, constructing a block with smart matching. The tests pass but I feel the right solution may be fixing the Perl6Regex structure, even because similar code to build the subset type is used in make_anon_subset. Sadly, it's the first time I dive into the rakudo source and I do not feel comfortable doing that. Attached is the patch, and my minimal test suite, which should probably go into the perl6 spec, which tests the definition of subsets but not with a regex literal. All tests pass, and spectest behaves the same as the unpatched version. patch2 Description: Binary data
Re: [S02] Sigils
Jonathan Lang wrote: From S02: -- Perl 6 includes a system of Bsigils to mark the fundamental structural type of a variable: $ scalar (object) @ ordered array % unordered hash (associative array) code/rule/token/regex :: package/module/class/role/subset/enum/type/grammar @@ multislice view of @ while we are at it: :: and are _really_ sigils for variables? They seem (to me) more akin to a literal syntax, and I wonder what would happen in a case like this: sub foo {} sub bar {} # currently syntax error in pugs, but if is a variable sigil # why I can't have it on a variable? my foo = bar; foo('hello') I have to understand that foo = somefunction is actually redefining the foo() sub? If not, which gets called in the above case? can I have access again to the original foo sub here? and in these context multi foo(Int $i) {...} multi foo(Str $i) {...} my foo = fooInt foo('hello') do I get an error, since we are using the variant defined for Ints or is the multiple dispatch called again? Same for :: ::Object = $?GRAMMAR is guaranteed to explode in my face or is it just a syntactic error (as it currently is in pugs) ?
cached trait specs
Hi everyone, A small request about the cached trait for functions that makes them memoized: would it be possible to make it parametric? I think it would be nice to have at least one variant sub foo is cached(max=$size) caching just the first $size results. Maybe it could also be useful to have a default size of the cache instead of letting it grow indefinitely? I can easily imagine RAMs suffering because someone used is cached in a bad place :) Also it would be quite useful, I think, to have another variant: sub foo is cached(using = $mapping) this way people could implement their own caching policies easily, i.e. FIFO buffer, most used, most expensive and so on. Or reload on-disk caches from run to run, and even the other suggestion could be implemented easily in terms of this. On the other hand, if the cached trait had a %.mapping attribute possible we could do this withouth making cached parametric, I mean: sub foo is cached {...} foo.mapping = $my_mapping but I think the other way it would be more clear.
explicit line termination with ;: why?
Hi everyone, I don't want to argue about the design of perl6[1], I just wonder: why the semicolon is still needed in the end of lines in perl6? I can think of different reasons (history, readability, easier parsing of multiline statements, force people to write one-line functions to avoid typing them :) but I'm curious to know the real one. Sorry if this is already been explained but my google-fu was not good enough to find an answer. [1] of course I actually do, but I know that I will be able to write my own Grammar, to scratch my Wannabe Language Designer itches ;)
Re: Regexp: s/at($pos)/$str/ should replace or add?
A. Pagaltzis wrote: Does it mean that basically the assertion is a character/string property instead of the character/string itself? No, it is a zero-width assertion. `at(1)` means the position “between” the 0th and 1th character of the string. I see thank you Also, what is the correct way to replace the i-th character in a Str ? `substr`. Ah thank you again, my newbie-ness is extreme. But doesn't substr modify the string in place? Is there a side effect-free variant or should I just dup the str ?
Regexp: s/at($pos)/$str/ should replace or add?
Hello, sorry about the dumb question but I'm not sure I understand the at($pos) assertion. If I write something like my $s=hello s/at(1)/a/ I expected it to give me hallo whereas it give ms haello. Does it mean that basically the assertion is a character/string property instead of the character/string itself? Also, what is the correct way to replace the i-th character in a Str ? I can do (well, I can't cause pugs doesn't have subst, it seems) str.subst(/at($i)./,$other) but it seem unnecessarily verbose. Is there something else builtin? If not, wouldn't it be better if Str.subst could accept Ints and Ranges as the first argument?
take()'s return value
Hi everyone, I wonder: why does take inside a gather structure returns undef? I think it would be nicer if it could return the taken value, so that, for example one can write something like: say take 2 or like: while cond($n) { my $res = compute($n) $n /= take($res) } there is a reason why this is a completely stupid idea?
Re: 99problems: 9, 11, 13
Ovid ha scritto: 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. of course two solutions are better than one, I don't know why I didn't think of this :) It's not really my call, though. Commit bits are there for a reason :) true :)
99problems: 9, 11, 13
Hi people, I implemented 13 from scratch because I didn't know it was already solved, in this way sub encode_direct([EMAIL PROTECTED] is copy) returns Str { my ($packed, $count); while @array { if @array[0] eq @array[1] { $count++; } else { $packed ~=( $count ?? ($count+1) ~ @array[0] !! @array[0] ); $count=0; } @array.shift; } return $packed; } is encode_direct(),'', 'We should be able to encode_direct an empty list'; is encode_direct(a), 'a', '.. or a one-element list'; is encode_direct(a a), '2a', '.. or a n-ary list with always same element'; is encode_direct(a a a a b c c a a d e e e e), '4ab2c2ad4e', '.. or a generic list'; I think it's cleaner, shall I commit? And in general, I could use a $first variable to keep the value in @array[0], but I don't think it adds in readability, terseness and (if the interpreter is Smart Enough(TM) ) not even in efficiency, what would be the right thing to do? Thanks again for any comment.
Re: perl6-ish idiom for code and tests in one file
Larry Wall ha scritto: On Fri, Jan 05, 2007 at 01:40:44PM +0200, Gaal Yahas wrote: : I think it should be possible and nice to use a macro (possibly a : standard subroutine, I'm not sure) like : : testing { : ok foo; : } : : would it make sense or I'm just crazy? : : I like the approach. I think you eventually just want: sub MAIN { use Test; ok foo; } nice, I didn't know this but the autocall into MAIN is not yet implemented. You can emulate by putting something like this as the last line in your file: MAIN(@ARGS), exit if $?FILE eq $*PROGRAM_NAME; or maybe MAIN(@ARGS), exit unless caller; if/when that works as in Perl 5. When the autocall is implemented you can just delete that line. seems a nice solution, and given that sooner or later the former will work I don't think that I need my testing() hack,
Re: perl6-ish idiom for code and tests in one file
Larry Wall ha scritto: but the autocall into MAIN is not yet implemented. You can emulate by putting something like this as the last line in your file: MAIN(@ARGS), exit if $?FILE eq $*PROGRAM_NAME; or maybe MAIN(@ARGS), exit unless caller; if/when that works as in Perl 5. When the autocall is implemented you can just delete that line. mh.. this does seem to have issues cause the MAIN somehow overlap, maybe because I'm loading other file through require ? Anyway I didn't know about caller and it seems to work, so I just put unless caller as the top of the block and everything is fine, thanks everyone again :)
perl6-ish idiom for code and tests in one file
Hi everyone, supposing that I want to keep code and tests in one single file, is there a common idiom to do that? At the moment I'm going with something like: if $?FILE == $*PROGRAM_NAME { use Test; plan 1; ok foo(); } but this seem unnecessarily verbose. Is there some standard idiom or function in Test.pm that allows this kind of thing with a nicer interface? I think it should be possible and nice to use a macro (possibly a standard subroutine, I'm not sure) like testing { ok foo; } would it make sense or I'm just crazy?
Re: 99 problems in Perl6: 32 and a question on number coercion
Steffen Schwigon ha scritto: Hi! gabriele renzi [EMAIL PROTECTED] writes: Hi everyone! I solved the (easy) problem 32, implementing gcd($a,$b). You can check the code in the repository or on the web[1] I looked at [1]. What's the purpose of multi in this case? (Maybe you wanted to write it as more than one subs, did you?) look the comment: # Yet, it should be possible to define it even for commutative rings # other than Integers, so we use a multi sub. I think that in these examples we should respect the old good programmin' habits, including the stay open for extension idea. If we'd use a normal sub we would limit all the future user of gcd (which I expect to be legions ;) to using Int. snip Could someone explain me what is the expected behaviour? Last time I experimented with this, the type system in Pugs looked unfinished. Type constraints were syntactically accepted but worked similar to typeless code in Perl5. I'm not sure about the current state. I see Anyway, in your example I hadn't expected a value coercion (from 10.1 to 10), but something like an error if the type doesn't match. this is what I'd like to see too, since I think it could help avoiding casual errors, and the extensibility of the system is still safe because of the multi things. But I remember reading that, by default, perl6 will try to autocoerce arguments. -- blog en: http://www.riffraff.info blog it: http://riffraff.blogsome.com jabber : rff.rff at gmail dot com
Re: gather { if $xy.was_taken { ... } }
Gilbert R. Röhrbein ha scritto: Hi, I'm new to Perl 6 (and perl). Is there a way to check inside a gather-block if something was allready taken? I thought it would look like one of the following, but it doesnt work on my pugs 6.2.13. gather { for 1..100 { take $_ unless @_.contains(42) } } I think in place of @_ you'd want gathered which gives you access to the anonymous array being constructed from gather/take. But AFAIK this does not work in pugs 6.2.13 :/
99 problems in Perl6: problem 28
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= [a b c],[d e],[f g h],[d e],[i j k l],[m n],[o]; my @expected= [o],[d e],[d e],[m n],[a b c],[f g h],[i j 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= [o],[i j k l],[a b c],[f g h],[d e],[d e],[m 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
Re: 99 problems in Perl6: problem 28
Ovid ha scritto: Ah, nice to see someone else tackling the problems. yes, it was such a nice idea :) 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) By the way, any comments on the code? :)
99 problems in Perl6: 32 and a question on number coercion
Hi everyone! I solved the (easy) problem 32, implementing gcd($a,$b). You can check the code in the repository or on the web[1] But while writing this I noticed that a function written as sub gcd(Int $a, Int $b) still accepts float/rational values in input. I think I read once that a variable of type Int would accept these kind of assignment but that the value would be coerced to the new type of the variable, i.e. my Int $a= 10.1 #= 10 Could someone explain me what is the expected behaviour? [1] http://sial.org/pbot/22088 -- blog en: http://www.riffraff.info blog it: http://riffraff.blogsome.com jabber : rff.rff at gmail dot com