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

problem using Duration #5071

Closed
p6rt opened this issue Jan 21, 2016 · 7 comments
Closed

problem using Duration #5071

p6rt opened this issue Jan 21, 2016 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Jan 21, 2016

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

Searchable as RT127339$

@p6rt
Copy link
Author

p6rt commented Jan 21, 2016

From @MARTIMM

l.s.

In REPL;

my Duration $d .= new(10);
10
$d += 1000
1010
$d -= 900
110
$d *= 2
Type check failed in assignment to $d; expected Duration but got Num
  in block <unit> at <unknown file> line 1
$d /= 2
Type check failed in assignment to $d; expected Duration but got Num
  in block <unit> at <unknown file> line 1
$d * 2
220
$d .= new($d * 2)
220

Conclusion is that += and -= works but *= and /= do not while $d * 2
gives a proper answer without problem. Only last method works.

Greetings
Marcel Timmerman

This is Rakudo version 2015.12-201-g2a8ca94 built on MoarVM version
2015.12-29-g8079ca5
implementing Perl 6.c.

@p6rt
Copy link
Author

p6rt commented Jan 22, 2016

From @smls

This is the root of the problem​:

  ➜ say ($d + 2).WHAT;
  (Duration)
 
  ➜ say ($d * 2).WHAT'
  (Num)

The behavior of += and *= is just a consequence of that.

@p6rt
Copy link
Author

p6rt commented Jan 22, 2016

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

@p6rt
Copy link
Author

p6rt commented Jan 22, 2016

From @MARTIMM

On 01/22/2016 01​:52 PM, Sam S. via RT wrote​:

This is the root of the problem​:

➜ say ($d + 2).WHAT;
(Duration)

➜ say ($d * 2).WHAT'
(Num)

The behavior of += and *= is just a consequence of that.
Then the question remains why the multiplication results in Num if it
multiplies with an integer. Besides, addition of a Num still becomes a
Duration. See following REPL;

my Duration $d .= new(10);
10
$d += 1.1
11.1
$d += 1.1
12.2
$d.WHAT.say
(Duration)

@p6rt
Copy link
Author

p6rt commented Aug 6, 2016

From @zoffixznet

Then the question remains why the multiplication results in Num if it multiplies with an integer

It's merely a matter that such things require addition of three extra operators per operation (e.g. Duration * Duration, Duration * Num, Num * Duration). Custom operators were added for common operations, such as addition, but rarer ones were omitted. For example, you can subtract two Instants,
since we commonly do {now - INIT now} but there's no operator to subtract an Instant from an arbitrary number.

There's *, /, div, and mod just for basic math. If we count Duration and Instant only that's 24 extra operators to write, debug, maintain, and most importantly compile and load on program start.

Since in rarer use cases for which there isn't currently an operator the programmer can simply coerce the value to anything they want, it makes sense to not create custom operators for every imaginable case.

For those reasons, I'm rejecting this ticket.

--
Cheers,
ZZ | https://twitter.com/zoffix

@p6rt
Copy link
Author

p6rt commented Aug 6, 2016

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

@p6rt p6rt closed this as completed Aug 6, 2016
@p6rt
Copy link
Author

p6rt commented Aug 7, 2016

From @MARTIMM

On 08/06/2016 05​:39 AM, Zoffix Znet via RT wrote​:

Then the question remains why the multiplication results in Num if it multiplies with an integer
It's merely a matter that such things require addition of three extra operators per operation (e.g. Duration * Duration, Duration * Num, Num * Duration). Custom operators were added for common operations, such as addition, but rarer ones were omitted. For example, you can subtract two Instants,
since we commonly do {now - INIT now} but there's no operator to subtract an Instant from an arbitrary number.

There's *, /, div, and mod just for basic math. If we count Duration and Instant only that's 24 extra operators to write, debug, maintain, and most importantly compile and load on program start.

Since in rarer use cases for which there isn't currently an operator the programmer can simply coerce the value to anything they want, it makes sense to not create custom operators for every imaginable case.

For those reasons, I'm rejecting this ticket.

Hi Zoffix,

I understand completely, thanks for looking into it.

Marcel

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