Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

man, max should accept code block that defines ordering #653

Closed
p6rt opened this issue Jan 25, 2009 · 6 comments
Closed

man, max should accept code block that defines ordering #653

p6rt opened this issue Jan 25, 2009 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Jan 25, 2009

Migrated from rt.perl.org#62742 (status was 'resolved')

Searchable as RT62742$

@p6rt
Copy link
Author

p6rt commented Jan 25, 2009

From dave.whipp@gmail.com

According to S29, the "min" and "max" methods should accept the same
ordering args as "sort"​:

say "{(1..10).sort​: { ($_-3) * ($_-5) }}";

4 3 5 2 6 1 7 8 9 10

say (1..10).min​: { ($_-3) * ($_-5) };

4

The former works as expected​: the latter fails​:

% ./perl6 -e 'say (1..10).min​: { ($_-3) * ($_-5) }'
too many arguments passed (3) - 1 params expected
current instr.​: 'parrot;Range;min' pc 7736 (src/classes/Range.pir​:143)
called from Sub '_block14' pc 106 (EVAL_20​:49)
called from Sub '!UNIT_START' pc 18152 (src/builtins/guts.pir​:321)
called from Sub 'parrot;PCT;HLLCompiler;eval' pc 950
(src/PCT/HLLCompiler.pir​:527)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1496
(src/PCT/HLLCompiler.pir​:787)
called from Sub 'parrot;Perl6;Compiler;main' pc 22199 (perl6.pir​:159)
Exit 1

@p6rt
Copy link
Author

p6rt commented Jan 26, 2009

From @bacek

Dave Whipp wrote​:

According to S29, the "min" and "max" methods should accept the same
ordering args as "sort"​:

say "{(1..10).sort​: { ($_-3) * ($_-5) }}";

4 3 5 2 6 1 7 8 9 10

say (1..10).min​: { ($_-3) * ($_-5) };

4

Attached patch for fixing Range.min, max and minmax.

Spectest updated in r25027.

--
Bacek

@p6rt
Copy link
Author

p6rt commented Jan 26, 2009

From @bacek

range_minmax.patch
commit 765c12dc6eb733b87e190ce39519af978ad66a79
Author: Vasily Chekalkin <bacek@bacek.com>
Date:   Mon Jan 26 09:20:45 2009 +1100

    Proper implement min, max and minmax on Ranges.

diff --git a/languages/perl6/src/classes/Range.pir b/languages/perl6/src/classes/Range.pir
index a3bc69e..9298f89 100644
--- a/languages/perl6/src/classes/Range.pir
+++ b/languages/perl6/src/classes/Range.pir
@@ -136,19 +136,43 @@ just return a clone of the Range.
 
 .namespace ['Range']
 
-.sub 'max' :method
+.sub 'max' :method :multi(_)
+    .param pmc by              :optional
+    .param int has_by          :opt_flag
+    if has_by goto have_by
     .tailcall self.'to'()
+
+  have_by:
+    # Flatten range and delegate call Array.max
+    $P0 = self.'list'()
+    .tailcall $P0.'max'(by)
 .end
 
-.sub 'min' :method
+.sub 'min' :method :multi(_)
+    .param pmc by              :optional
+    .param int has_by          :opt_flag
+    if has_by goto have_by
     .tailcall self.'from'()
+
+  have_by:
+    # Flatten range and delegate call Array.min
+    $P0 = self.'list'()
+    .tailcall $P0.'min'(by)
 .end
 
-.sub 'minmax' :method
+.sub 'minmax' :method :multi(_)
+    .param pmc by              :optional
+    .param int has_by          :opt_flag
+    if has_by goto have_by
     $P0 = self.'from'()
     $P1 = self.'to'()
     $P2 = get_hll_global 'list'
     .tailcall $P2($P0, $P1)
+
+  have_by:
+    # Flatten range and delegate call Array.minmax
+    $P0 = self.'list'()
+    .tailcall $P0.'minmax'(by)
 .end
 
 

@p6rt
Copy link
Author

p6rt commented Jan 26, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented May 1, 2009

From @jnthn

On Sun Jan 25 09​:09​:51 2009, dave.whipp@​gmail.com wrote​:

According to S29, the "min" and "max" methods should accept the same
ordering args as "sort"​:

say "{(1..10).sort​: { ($_-3) * ($_-5) }}";

4 3 5 2 6 1 7 8 9 10

say (1..10).min​: { ($_-3) * ($_-5) };

4

The former works as expected​: the latter fails​:

% ./perl6 -e 'say (1..10).min​: { ($_-3) * ($_-5) }'
too many arguments passed (3) - 1 params expected
current instr.​: 'parrot;Range;min' pc 7736 (src/classes/Range.pir​:143)
called from Sub '_block14' pc 106 (EVAL_20​:49)
called from Sub '!UNIT_START' pc 18152 (src/builtins/guts.pir​:321)
called from Sub 'parrot;PCT;HLLCompiler;eval' pc 950
(src/PCT/HLLCompiler.pir​:527)
called from Sub 'parrot;PCT;HLLCompiler;command_line' pc 1496
(src/PCT/HLLCompiler.pir​:787)
called from Sub 'parrot;Perl6;Compiler;main' pc 22199 (perl6.pir​:159)
Exit 1

Both min and max now have a single-arity form as of git 44c4879, which
seem to give the expected results. Added a couple of tests in
S32-list/minmax.t. Resolving ticket.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented May 1, 2009

@jnthn - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed May 1, 2009
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant