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

Set operators unfriendly to mutable types #6632

Closed
p6rt opened this issue Oct 23, 2017 · 12 comments
Closed

Set operators unfriendly to mutable types #6632

p6rt opened this issue Oct 23, 2017 · 12 comments

Comments

@p6rt
Copy link

p6rt commented Oct 23, 2017

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

Searchable as RT132352$

@p6rt
Copy link
Author

p6rt commented Oct 23, 2017

From @zoffixznet

Set operators are a lot less useful with mutable types, like SetHash, because
even when one of the operands is a SetHash, they still return a Set, making
constructs like `∖=` or `∪=` entirely unusable​:

  my $days = SetHash.new​: Date.today … Date.new​: '2014-04-02';
  $days ∖= $days.grep​: *.key.day-of-week > 5;
  dd $days.^name; # "Set"
  $days{Date.today}​:delete; # Cannot call 'DELETE-KEY' on an immutable 'Set'

@p6rt
Copy link
Author

p6rt commented Oct 23, 2017

From @smls

On Mon, 23 Oct 2017 05​:23​:55 -0700, cpan@​zoffix.com wrote​:

Set operators are a lot less useful with mutable types, like SetHash,
because
even when one of the operands is a SetHash, they still return a Set,
making
constructs like `∖=` or `∪=` entirely unusable​:

my $days = SetHash.new​: Date.today … Date.new​: '2014-04-02';
$days ∖= $days.grep​: *.key.day-of-week > 5;
dd $days.^name; # "Set"
$days{Date.today}​:delete; # Cannot call 'DELETE-KEY' on an immutable
'Set'

I don't think setty operators always returning Set, is that different from listy operators/methods (Z, grep, map...) always returning Seq.

For example, when you write​:

  @​foo .= grep​: * %% 2;

Then the grep returns a Seq, and and its the assignment to the Array variable which makes sure that in the end you'll have the results as an Array. (Still the same Array, in fact, just with new contents.)

If you were to use a Scalar variable, you would get essentially the same issue as in your quoted Set example​:

  $foo .= grep​: * %% 2; # Oops, $foo is now an immutable Seq.

The "solution", IMO, would not be to make your quoted example work (by adding further special cases to the return types of the setty operators or otherwise), but rather to make the following variation of it work​:

  my %days is SetHash = Date.today … Date.new​: '2014-04-02';

  %days ∖= %days.grep​: *.key.day-of-week > 5;

  %days{Date.today}​:delete;

...and then promote %-sigiled SetHash variables as the recommended way to store SetHash'es.

It should be possible to make this last example work by implementing `method STORE` for type SetHash, right?

(That it currently doesn't, may well be an oversight rather than a design choice.)

@p6rt
Copy link
Author

p6rt commented Oct 23, 2017

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

@p6rt
Copy link
Author

p6rt commented Oct 24, 2017

From @zoffixznet

On Mon, 23 Oct 2017 09​:12​:58 -0700, smls75@​gmail.com wrote​:

On Mon, 23 Oct 2017 05​:23​:55 -0700, cpan@​zoffix.com wrote​:

Set operators are a lot less useful with mutable types, like SetHash,
because
even when one of the operands is a SetHash, they still return a Set,
making
constructs like `∖=` or `∪=` entirely unusable​:

my $days = SetHash.new​: Date.today … Date.new​: '2014-04-02';
$days ∖= $days.grep​: *.key.day-of-week > 5;
dd $days.^name; # "Set"
$days{Date.today}​:delete; # Cannot call 'DELETE-KEY' on an immutable
'Set'

I don't think setty operators always returning Set, is that different
from listy operators/methods (Z, grep, map...) always returning Seq.

For example, when you write​:

@​foo .= grep​: * %% 2;

Then the grep returns a Seq, and and its the assignment to the Array
variable which makes sure that in the end you'll have the results as
an Array. (Still the same Array, in fact, just with new contents.)

If you were to use a Scalar variable, you would get essentially the
same issue as in your quoted Set example​:

$foo .= grep​: * %% 2; # Oops, $foo is now an immutable Seq.

The "solution", IMO, would not be to make your quoted example work (by
adding further special cases to the return types of the setty
operators or otherwise), but rather to make the following variation of
it work​:

my %days is SetHash = Date.today … Date.new​: '2014-04-02';

%days ∖= %days.grep​: *.key.day-of-week > 5;

%days{Date.today}​:delete;

...and then promote %-sigiled SetHash variables as the recommended way
to store SetHash'es.

It should be possible to make this last example work by implementing
`method STORE` for type SetHash, right?

(That it currently doesn't, may well be an oversight rather than a
design choice.)

Thanks for clarifying. Yeah, it looks better if it had a % sigil on it too.

Gonna reject this issue and open a new one on our GitHub tracker[^1] to take it for a spin

[1] https://github.com/rakudo/rakudo/issues

@p6rt
Copy link
Author

p6rt commented Oct 24, 2017

From @zoffixznet

Rejecting 'cause it's a misunderstanding of how things work in OP.

Opened the suggestion for making `%` sigil work in rakudo/rakudo#1203

@p6rt
Copy link
Author

p6rt commented Oct 24, 2017

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

@p6rt
Copy link
Author

p6rt commented Oct 30, 2017

From @lizmat

On 24 Oct 2017, at 12​:56, Zoffix Znet via RT <perl6-bugs-followup@​perl.org> wrote​:
On Mon, 23 Oct 2017 09​:12​:58 -0700, smls75@​gmail.com wrote​:

On Mon, 23 Oct 2017 05​:23​:55 -0700, cpan@​zoffix.com wrote​:
The "solution", IMO, would not be to make your quoted example work (by
adding further special cases to the return types of the setty
operators or otherwise), but rather to make the following variation of
it work​:

my %days is SetHash = Date.today … Date.new​: '2014-04-02';

%days ∖= %days.grep​: *.key.day-of-week > 5;

%days{Date.today}​:delete;

...and then promote %-sigiled SetHash variables as the recommended way
to store SetHash'es.

It should be possible to make this last example work by implementing
`method STORE` for type SetHash, right?

(That it currently doesn't, may well be an oversight rather than a
design choice.)

Commit b6a4d5b555520451c5c8a made this possible​:

my %d is SetHash = Date.today .. Date.new("2017-11-30”);
%d .= grep​: *.key.day-of-week > 5;
dd %d;

SetHash.new(Date.new(2017,11,5),Date.new(2017,11,12),Date.new(2017,11,26),Date.new(2017,11,4),Date.new(2017,11,19),Date.new(2017,11,11),Date.new(2017,11,18),Date.new(2017,11,25))

@p6rt
Copy link
Author

p6rt commented Nov 18, 2017

From @AlexDaniel

Does it mean that this now needs tests?

On 2017-10-30 06​:42​:25, elizabeth wrote​:

On 24 Oct 2017, at 12​:56, Zoffix Znet via RT <perl6-bugs-
followup@​perl.org> wrote​:
On Mon, 23 Oct 2017 09​:12​:58 -0700, smls75@​gmail.com wrote​:

On Mon, 23 Oct 2017 05​:23​:55 -0700, cpan@​zoffix.com wrote​:
The "solution", IMO, would not be to make your quoted example work
(by
adding further special cases to the return types of the setty
operators or otherwise), but rather to make the following variation
of
it work​:

my %days is SetHash = Date.today … Date.new​: '2014-04-02';

%days ∖= %days.grep​: *.key.day-of-week > 5;

%days{Date.today}​:delete;

...and then promote %-sigiled SetHash variables as the recommended
way
to store SetHash'es.

It should be possible to make this last example work by implementing
`method STORE` for type SetHash, right?

(That it currently doesn't, may well be an oversight rather than a
design choice.)

Commit b6a4d5b555520451c5c8a made this possible​:

my %d is SetHash = Date.today .. Date.new("2017-11-30”);
%d .= grep​: *.key.day-of-week > 5;
dd %d;

SetHash.new(Date.new(2017,11,5),Date.new(2017,11,12),Date.new(2017,11,26),Date.new(2017,11,4),Date.new(2017,11,19),Date.new(2017,11,11),Date.new(2017,11,18),Date.new(2017,11,25))

@p6rt
Copy link
Author

p6rt commented Nov 18, 2017

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

@p6rt
Copy link
Author

p6rt commented Nov 18, 2017

From @lizmat

Hmmm…. I guess this one does… good point! :-)

On 18 Nov 2017, at 17​:57, Aleks-Daniel Jakimenko-Aleksejev via RT <perl6-bugs-followup@​perl.org> wrote​:

Does it mean that this now needs tests?

On 2017-10-30 06​:42​:25, elizabeth wrote​:

On 24 Oct 2017, at 12​:56, Zoffix Znet via RT <perl6-bugs-
followup@​perl.org> wrote​:
On Mon, 23 Oct 2017 09​:12​:58 -0700, smls75@​gmail.com wrote​:

On Mon, 23 Oct 2017 05​:23​:55 -0700, cpan@​zoffix.com wrote​:
The "solution", IMO, would not be to make your quoted example work
(by
adding further special cases to the return types of the setty
operators or otherwise), but rather to make the following variation
of
it work​:

my %days is SetHash = Date.today … Date.new​: '2014-04-02';

%days ∖= %days.grep​: *.key.day-of-week > 5;

%days{Date.today}​:delete;

...and then promote %-sigiled SetHash variables as the recommended
way
to store SetHash'es.

It should be possible to make this last example work by implementing
`method STORE` for type SetHash, right?

(That it currently doesn't, may well be an oversight rather than a
design choice.)

Commit b6a4d5b555520451c5c8a made this possible​:

my %d is SetHash = Date.today .. Date.new("2017-11-30”);
%d .= grep​: *.key.day-of-week > 5;
dd %d;

SetHash.new(Date.new(2017,11,5),Date.new(2017,11,12),Date.new(2017,11,26),Date.new(2017,11,4),Date.new(2017,11,19),Date.new(2017,11,11),Date.new(2017,11,18),Date.new(2017,11,25))

@p6rt
Copy link
Author

p6rt commented Dec 12, 2017

From @zoffixznet

I see tests already exists for this ticket in S02-types/sethash.t

@p6rt
Copy link
Author

p6rt commented Dec 12, 2017

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

@p6rt p6rt closed this as completed Dec 12, 2017
@p6rt p6rt added the testneeded label Jan 5, 2020
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