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

.sort doesn't accept &rand (or zero-arg subs in general) in Rakudo #1190

Closed
p6rt opened this issue Aug 1, 2009 · 13 comments
Closed

.sort doesn't accept &rand (or zero-arg subs in general) in Rakudo #1190

p6rt opened this issue Aug 1, 2009 · 13 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 1, 2009

Migrated from rt.perl.org#68112 (status was 'rejected')

Searchable as RT68112$

@p6rt
Copy link
Author

p6rt commented Aug 1, 2009

From @masak

<masak> rakudo​: say (1..10).sort(&rand)
<jnthn> Yes.
<p6eval> rakudo e02bc0​: OUTPUT«too many arguments passed - 0 params
expected␤in sub rand [...]
<masak> shouldn't that work?
<jnthn> rakudo​: say &rand.multi
<p6eval> rakudo e02bc0​: OUTPUT«0␤»
<jnthn> rakudo​: say &rand.signature.perl
<p6eval> rakudo e02bc0​: OUTPUT«​:(Any *@​args)␤»
<jnthn> rakudo​: say &rand.arity
<masak> jnthn​: wrong, right?
<p6eval> rakudo e02bc0​: OUTPUT«0␤»
<pmichaud> Note that slurpies are supposed to be Object, not Any
<jnthn> masak​: Well the answers can't both be right. ;-)
<jnthn> Anyway, rand is 0-ary, at least as far as Rakudo knows it.
<masak> jnthn​: right, so &sort should accept it.
<jnthn> So in your sort example, Rakudo doesn't really know what to do
with an 0-ary.
<Tene> *any* 0-ary sub passed to sort is effectively a random sort.
<Tene> so we can optimize that and just return the list in the same
order it was passed. :)
<pmichaud> well, it depends on the 0-ary.
<pmichaud> a 0-ary sub that always returns zero should end up not
modifying the sort
<jnthn> Aye.
<jnthn> True.
<jnthn> It's odd anyway. ;-)
<Tene> is Perl 6's sort guaranteed to be stable?
<masak> Tene​: aye.
<jnthn> But maybe sort could be made to understnad 0-ary blocks.
<masak> jnthn​: spec says it should.
<jnthn> ah, ok
<jnthn> Then, fix it. :-)
* masak submits rakudobug
<jnthn> Or rakudobug. ;)
<pmichaud> the spec says it supports 0-ary blocks?
<masak> pmichaud​: aye.
<pmichaud> weird
<masak> aye.

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

From @bbkr

On Kiev build​:

$ perl6 -e 'say (1..10).sort(&rand)'
12345678910

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

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

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

From @bbkr

tests added in
pugs/t/spec/S32-list/sort.t

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

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

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

From @masak

On Mon Jul 12 08​:07​:38 2010, bbkr wrote​:

On Kiev build​:

$ perl6 -e 'say (1..10).sort(&rand)'
12345678910

I'd argue that this is the wrong behavior. I'd like for it to behave the same way this does​:

(1..10).sort( { rand } )
9 8 5 3 10 1 2 4 6 7

Oh, and I get a different result with Rakudo 2010.06-219-g7579f7a​:

(1..10).sort( &rand )
too many arguments passed - 0 params expected

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S32-list/sort.t

commit 8a55371caf69c520e9c5272fa84b24d6a4f33682
Author​: bbkr <bbkr@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Mon Jul 12 15​:16​:59 2010 +0000

  [t/spec] tests for RT #​68112 sort doesnt accept &rand (or zero-arg subs in general)
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31642 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S32-list/sort.t b/t/spec/S32-list/sort.t
index 2f82da3..de6f71a 100644
--- a/t/spec/S32-list/sort.t
+++ b/t/spec/S32-list/sort.t
@@ -1,6 +1,6 @@
 use v6;
 use Test;
-plan 29;
+plan 31;
 
 # L<S32::Containers/"List"/"=item sort">
 
@@ -210,4 +210,13 @@ plan 29;
         'sort by class name';
 }
 
+# RT #68112
+{
+    sub foo () { 0 }
+    lives_ok { (1..10).sort(&foo) },
+        'sort accepts 0-arity method';
+    lives_ok { (1..10).sort(&rand) },
+        'sort accepts rand method';
+}
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

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

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

From @bbkr

[17​:24] <bbkr> masak​: should i revert it from test suite untill expected
behavior is determined?
[17​:25] <moritz_> bbkr​: just fudge it for now

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S32-list/sort.t

commit dda2c2b53e5d047cff3110138f5982f3e8b2270d
Author​: bbkr <bbkr@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Mon Jul 12 15​:35​:39 2010 +0000

  [t/spec] tests for RT #​68112 sort doesnt accept &rand (or zero-arg subs in general) - fudged
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;31643 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S32-list/sort.t b/t/spec/S32-list/sort.t
index de6f71a..1e0d219 100644
--- a/t/spec/S32-list/sort.t
+++ b/t/spec/S32-list/sort.t
@@ -211,6 +211,7 @@ plan 31;
 }
 
 # RT #68112
+#?rakudo skip "determine behavior of 0-arity methods passed to sort"
 {
     sub foo () { 0 }
     lives_ok { (1..10).sort(&foo) },

@p6rt
Copy link
Author

p6rt commented Jul 12, 2010

From @bbkr

[17​:42] <masak> bbkr​: re "determine behavior of 0-arity methods passed
to sort" -- (1) it's not a method :) (2) I think the behavior is already
clear, at least if the spec says this should act like a Schwartzian
transform, which I think it does.
[17​:43] <masak> then the behavior is "collect all (random) values, sort
on them".
[17​:46] <bbkr> masak​: thanks, I didn't know about Schwartzian transform.
adding this info to ticket.

@p6rt
Copy link
Author

p6rt commented May 17, 2012

From @masak

On Mon Jul 12 08​:46​:21 2010, bbkr wrote​:

[17​:42] <masak> bbkr​: re "determine behavior of 0-arity methods passed
to sort" -- (1) it's not a method :) (2) I think the behavior is
already
clear, at least if the spec says this should act like a Schwartzian
transform, which I think it does.
[17​:43] <masak> then the behavior is "collect all (random) values,
sort
on them".
[17​:46] <bbkr> masak​: thanks, I didn't know about Schwartzian
transform.
adding this info to ticket.

Changing my mind on this one. use .pick(*) if you want .sort(&rand)
semantics. Wrap your nullary function in a unary or binary function if
you want something more advanced.

Rejecting ticket.

@p6rt
Copy link
Author

p6rt commented May 17, 2012

@masak - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed May 17, 2012
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant