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

.grep 'is rw' but .first isn't in Rakudo #3180

Closed
p6rt opened this issue Jul 4, 2013 · 6 comments
Closed

.grep 'is rw' but .first isn't in Rakudo #3180

p6rt opened this issue Jul 4, 2013 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Jul 4, 2013

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

Searchable as RT118755$

@p6rt
Copy link
Author

p6rt commented Jul 4, 2013

From @masak

<colomon> does this imply we should have (for instance) first-rw,
which returns the container of the first value that smartmatches?
<colomon> or perhaps more interestingly, grep-rw?
<pmichaud> I think that .first perhaps ought to be "is rw"
<pmichaud> grep is already rw-like, or should be.
<pmichaud> grep returns the elements maching a criteria, not just the
values matching a criteria
<colomon> r​: my @​a = 1..10; @​a.grep(* %% 2).>>++; say @​a
<camelia> rakudo 8a76ba​: OUTPUT«1 3 3 5 5 7 7 9 9 11␤»
* colomon 's head explodes
<masak> if .grep works like that, surely .first should as well :)
<masak> r​: my @​a = 1..10; @​a.first(* %% 2).>>++; say @​a
<camelia> rakudo 8a76ba​: OUTPUT«Cannot modify an immutable [BLA BLA BLA]
* masak submits rakudobug
<pmichaud> note that grep works like that in p5 as well
* colomon is split between one side that says "THAT'S AWESOME!" and
another that says "That's a grotesque distortion of what should be a
nice functional method."
<pmichaud> in some sense, it *is* a functional method in this form.
It's returning exactly the elements that matched (the containers),
without imposing a decontainerize operation on them
<pmichaud> if you decontainerize, you're not getting the elements that
matched, you're getting the values of the elements that matched.

@p6rt
Copy link
Author

p6rt commented Sep 3, 2014

@coke - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Sep 3, 2014

From @coke

On Thu Jul 04 09​:28​:09 2013, masak wrote​:

<colomon> does this imply we should have (for instance) first-rw,
which returns the container of the first value that smartmatches?
<colomon> or perhaps more interestingly, grep-rw?
<pmichaud> I think that .first perhaps ought to be "is rw"
<pmichaud> grep is already rw-like, or should be.
<pmichaud> grep returns the elements maching a criteria, not just the
values matching a criteria
<colomon> r​: my @​a = 1..10; @​a.grep(* %% 2).>>++; say @​a
<camelia> rakudo 8a76ba​: OUTPUT«1 3 3 5 5 7 7 9 9 11␤»
* colomon 's head explodes
<masak> if .grep works like that, surely .first should as well :)
<masak> r​: my @​a = 1..10; @​a.first(* %% 2).>>++; say @​a
<camelia> rakudo 8a76ba​: OUTPUT«Cannot modify an immutable [BLA BLA BLA]
* masak submits rakudobug
<pmichaud> note that grep works like that in p5 as well
* colomon is split between one side that says "THAT'S AWESOME!" and
another that says "That's a grotesque distortion of what should be a
nice functional method."
<pmichaud> in some sense, it *is* a functional method in this form.
It's returning exactly the elements that matched (the containers),
without imposing a decontainerize operation on them
<pmichaud> if you decontainerize, you're not getting the elements that
matched, you're getting the values of the elements that matched.

13​:17 <+dalek> rakudo/nom​: 07ef21e | duff++ | src/core/Any.pm​:
13​:17 <+dalek> rakudo/nom​: Fixes RT #​118755
13​:17 <+dalek> rakudo/nom​: review​:
  rakudo/rakudo@07ef21ed55

Closable with tests?

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Oct 16, 2014

From @usev6

This works now​:

$ perl6-m -e 'my @​a = 1..10; @​a.first(* %% 2).++; say @​a'
1 3 3 4 5 6 7 8 9 10

I added a test for this (and for the example with grep) to S32-list/first.t and S32-list/grep.t, respectively, with the following commit​: Raku/roast@4295bfcfae

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 16, 2014

From @usev6

This works now​:

$ perl6-m -e 'my @​a = 1..10; @​a.first(* %% 2).++; say @​a'
1 3 3 4 5 6 7 8 9 10

I added a test for this (and for the example with grep) to S32-list/first.t and S32-list/grep.t, respectively, with the following commit​: Raku/roast@4295bfcfae

@p6rt p6rt closed this as completed Oct 16, 2014
@p6rt
Copy link
Author

p6rt commented Oct 16, 2014

@usev6 - 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