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

.roll on a Range of Num ain't random #4759

Closed
p6rt opened this issue Nov 17, 2015 · 10 comments
Closed

.roll on a Range of Num ain't random #4759

p6rt opened this issue Nov 17, 2015 · 10 comments

Comments

@p6rt
Copy link

@p6rt p6rt commented Nov 17, 2015

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

Searchable as RT126664$

@p6rt
Copy link
Author

@p6rt p6rt commented Nov 17, 2015

From @gfldex

(0.1 .. 0.3).roll(10).say;

# OUTPUT«(0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1)␤»

# It should either be random or warn/fail at compile time.

@p6rt
Copy link
Author

@p6rt p6rt commented Nov 26, 2015

From @lizmat

On 17 Nov 2015, at 19​:16, Wenzel Peppmeyer (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Wenzel Peppmeyer
# Please include the string​: [perl #​126664]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=126664 >

(0.1 .. 0.3).roll(10).say;

# OUTPUT«(0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1)␤»

# It should either be random or warn/fail at compile time.

What did you expect? a selection of 0.1, 0.2, 0.3 ?? or 10 random values between 0.1 and 0.3 inclusive?

Liz

@p6rt
Copy link
Author

@p6rt p6rt commented Nov 26, 2015

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

@p6rt
Copy link
Author

@p6rt p6rt commented Nov 27, 2015

From @gfldex

On Thu, 26 Nov 2015, Elizabeth Mattijsen via RT wrote​:

(0.1 .. 0.3).roll(10).say;

What did you expect? a selection of 0.1, 0.2, 0.3 ?? or 10 random values between 0.1 and 0.3 inclusive?

I would (naive) expect 10x a value between 0.1 and 0.3 . Analog to​:

(0.1, 0.2, 0.3).roll(10).say;
# OUTPUT«(0.3 0.2 0.1 0.2 0.1 0.2 0.3 0.2 0.2 0.1)␤»

However, S03 is quite clear how Range is iterating.

0.1.succ == 1.1;

So incrementing by 0.1 can't work. It may be reasonable to fail as early
as possible for Range.roll on any Range that is neither Int nor Str on
both end points.

mfgwp

@p6rt
Copy link
Author

@p6rt p6rt commented Nov 27, 2015

From @moritz

On 11/26/2015 03​:36 PM, Wenzel P. P. Peppmeyer wrote​:

On Thu, 26 Nov 2015, Elizabeth Mattijsen via RT wrote​:

(0.1 .. 0.3).roll(10).say;

What did you expect? a selection of 0.1, 0.2, 0.3 ?? or 10 random
values between 0.1 and 0.3 inclusive?

I would (naive) expect 10x a value between 0.1 and 0.3 . Analog to​:

(0.1, 0.2, 0.3).roll(10).say;
# OUTPUT«(0.3 0.2 0.1 0.2 0.1 0.2 0.3 0.2 0.2 0.1)␤»

However, S03 is quite clear how Range is iterating.

0.1.succ == 1.1;

So incrementing by 0.1 can't work. It may be reasonable to fail as early
as possible for Range.roll on any Range that is neither Int nor Str on
both end points.

I don't think so. What's wrong with (1.1 .. 10.1).roll for example? It
has well-defined semantics.

People need to read docs occasionally, there's nothing we can do to
prevent them from abusing the core APIs, except by crippling them --
which isn't traditionally perl's approach.

Cheers,
Moritz

@p6rt
Copy link
Author

@p6rt p6rt commented Nov 27, 2015

From @pmichaud

The standard meaning of ".roll" is to randomly select elements
from a list. So I'd expect .roll on a Range to first convert the
Range to a list of values and then select from those.

If the intent is to select from the values 0.1, 0.2, 0.3, I'd expect
the programmer to write​:

  (0.1, 0.2, 0.3).roll(6)

If the intent is to select from a range of values incrementing by
0.1, then​:

  (0.1, 0.2 ... 10.1).roll(6)

If the intent is to generate six random Num values from a Range,
then it should probably be (I suspect this isn't implemented yet)​:

  (0.1 .. 0.3).rand xx 6

Pm

On Thu, Nov 26, 2015 at 03​:36​:49PM +0100, Wenzel P. P. Peppmeyer wrote​:

On Thu, 26 Nov 2015, Elizabeth Mattijsen via RT wrote​:

(0.1 .. 0.3).roll(10).say;

What did you expect? a selection of 0.1, 0.2, 0.3 ?? or 10 random values between 0.1 and 0.3 inclusive?

I would (naive) expect 10x a value between 0.1 and 0.3 . Analog to​:

(0.1, 0.2, 0.3).roll(10).say;
# OUTPUT«(0.3 0.2 0.1 0.2 0.1 0.2 0.3 0.2 0.2 0.1)␤»

However, S03 is quite clear how Range is iterating.

0.1.succ == 1.1;

So incrementing by 0.1 can't work. It may be reasonable to fail as early as
possible for Range.roll on any Range that is neither Int nor Str on both end
points.

mfgwp

@p6rt
Copy link
Author

@p6rt p6rt commented Nov 27, 2015

From @lizmat

So implemented with 61ea661d8dfc04acabf1eb46c

Liz

On 27 Nov 2015, at 17​:17, Patrick R. Michaud <pmichaud@​pobox.com> wrote​:

The standard meaning of ".roll" is to randomly select elements
from a list. So I'd expect .roll on a Range to first convert the
Range to a list of values and then select from those.

If the intent is to select from the values 0.1, 0.2, 0.3, I'd expect
the programmer to write​:

(0.1, 0.2, 0.3).roll(6)

If the intent is to select from a range of values incrementing by
0.1, then​:

(0.1, 0.2 ... 10.1).roll(6)

If the intent is to generate six random Num values from a Range,
then it should probably be (I suspect this isn't implemented yet)​:

(0.1 .. 0.3).rand xx 6

Pm

On Thu, Nov 26, 2015 at 03​:36​:49PM +0100, Wenzel P. P. Peppmeyer wrote​:

On Thu, 26 Nov 2015, Elizabeth Mattijsen via RT wrote​:

(0.1 .. 0.3).roll(10).say;

What did you expect? a selection of 0.1, 0.2, 0.3 ?? or 10 random values between 0.1 and 0.3 inclusive?

I would (naive) expect 10x a value between 0.1 and 0.3 . Analog to​:

(0.1, 0.2, 0.3).roll(10).say;
# OUTPUT«(0.3 0.2 0.1 0.2 0.1 0.2 0.3 0.2 0.2 0.1)␤»

However, S03 is quite clear how Range is iterating.

0.1.succ == 1.1;

So incrementing by 0.1 can't work. It may be reasonable to fail as early as
possible for Range.roll on any Range that is neither Int nor Str on both end
points.

mfgwp

@p6rt
Copy link
Author

@p6rt p6rt commented Jul 27, 2016

From @coke

On Fri Nov 27 09​:22​:20 2015, elizabeth wrote​:

So implemented with 61ea661d8dfc04acabf1eb46c

Liz

On 27 Nov 2015, at 17​:17, Patrick R. Michaud <pmichaud@​pobox.com>
wrote​:

The standard meaning of ".roll" is to randomly select elements
from a list. So I'd expect .roll on a Range to first convert the
Range to a list of values and then select from those.

If the intent is to select from the values 0.1, 0.2, 0.3, I'd expect
the programmer to write​:

(0.1, 0.2, 0.3).roll(6)

If the intent is to select from a range of values incrementing by
0.1, then​:

(0.1, 0.2 ... 10.1).roll(6)

If the intent is to generate six random Num values from a Range,
then it should probably be (I suspect this isn't implemented yet)​:

(0.1 .. 0.3).rand xx 6

Pm

On Thu, Nov 26, 2015 at 03​:36​:49PM +0100, Wenzel P. P. Peppmeyer
wrote​:

On Thu, 26 Nov 2015, Elizabeth Mattijsen via RT wrote​:

(0.1 .. 0.3).roll(10).say;

What did you expect? a selection of 0.1, 0.2, 0.3 ?? or 10 random
values between 0.1 and 0.3 inclusive?

I would (naive) expect 10x a value between 0.1 and 0.3 . Analog to​:

(0.1, 0.2, 0.3).roll(10).say;
# OUTPUT«(0.3 0.2 0.1 0.2 0.1 0.2 0.3 0.2 0.2 0.1)␤»

However, S03 is quite clear how Range is iterating.

0.1.succ == 1.1;

So incrementing by 0.1 can't work. It may be reasonable to fail as
early as
possible for Range.roll on any Range that is neither Int nor Str on
both end
points.

mfgwp

17​:37 [Coke] lizmat​: you last touched https://rt-archive.perl.org/perl6/Ticket/Display.html?id=126664 - is that closable now?
18​:31 < lizmat> [Coke]​: probably needs tests still

marking testneeded.
--
Will "Coke" Coleda

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 2, 2016

@p6rt
Copy link
Author

@p6rt p6rt commented Sep 2, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant