Navigation Menu

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

says "a comparison throws exception if either of its arguments is undefined" #2445

Closed
p6rt opened this issue Jul 3, 2011 · 10 comments
Closed
Labels

Comments

@p6rt
Copy link

p6rt commented Jul 3, 2011

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

Searchable as RT93978$

@p6rt
Copy link
Author

p6rt commented Jul 3, 2011

From @ronaldxs

In the spec here http://perlcabal.org/syn/S03.html#Comparison_semantics
at the bottom of the section it reads " a comparison naturally throws an
exception if either of its arguments is undefined".

As discussed on IRC here that does not match implementation or
TimToady's current view of design​:
http://irclog.perlgeek.de/perl6/2011-07-03#i_4051351 and
http://irclog.perlgeek.de/perl6/2011-07-03#i_4051461 .

The current implementation does​:

12​:43 PhatEddy
  perl6​: my Int $x; if $x<=0 { say 'cmp OK' }
12​:43 p6eval
  pugs, rakudo 72d158, niecza v7-11-g9ba8284​: OUTPUT«cmp OK␤»

@p6rt
Copy link
Author

p6rt commented Oct 7, 2011

From @coke

On Sun Jul 03 12​:27​:51 2011, ronaldxs wrote​:

In the spec here
http://perlcabal.org/syn/S03.html#Comparison_semantics
at the bottom of the section it reads " a comparison naturally throws
an
exception if either of its arguments is undefined".

Spec now says​:

Note that, like most other operators, a comparison naturally returns
failure if either of its arguments is undefined, and the general
policy on unthrown exceptions is that the exception is thrown as soon
as you try to use the exception as a real value.

Does that make this closable?

As discussed on IRC here that does not match implementation or
TimToady's current view of design​:
http://irclog.perlgeek.de/perl6/2011-07-03#i_4051351 and
http://irclog.perlgeek.de/perl6/2011-07-03#i_4051461 .

The current implementation does​:

12​:43 PhatEddy
perl6​: my Int $x; if $x<=0 { say 'cmp OK' }
12​:43 p6eval
pugs, rakudo 72d158, niecza v7-11-g9ba8284​: OUTPUT«cmp OK␤»

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Oct 7, 2011

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

@p6rt
Copy link
Author

p6rt commented May 11, 2013

From @FROGGS

TimToady​: yes, comparisons should return failure, not automatically
thrown an exception.

@p6rt
Copy link
Author

p6rt commented Jun 13, 2015

From @ronaldxs

On Sat May 11 13​:48​:34 2013, FROGGS.de wrote​:

TimToady​: yes, comparisons should return failure, not automatically
thrown an exception.

It throws an appropriate exception now. I think if a qualified person looked at this ticket they could close it.

Ron

@p6rt
Copy link
Author

p6rt commented Jul 10, 2015

From @coke

On Sat Jun 13 14​:37​:03 2015, ronaldxs wrote​:

On Sat May 11 13​:48​:34 2013, FROGGS.de wrote​:

TimToady​: yes, comparisons should return failure, not automatically
thrown an exception.

It throws an appropriate exception now. I think if a qualified person
looked at this ticket they could close it.

Ron

Note that the sample code needs to be formatted thusly​:

my Int $x; if $x <=0 { say 'cmp OK' }
Invocant requires a 'Int' instance, but a type object was passed. Did you forget a .new?

This seems to jibe with expectations. Added tests to S03-operators/misc.t .... but a nearly identical test for Str doesn't fail the same way. Test todo'd, needs some work.
--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Oct 25, 2015

From @usev6

On Fri Jul 10 14​:20​:06 2015, coke wrote​:

On Sat Jun 13 14​:37​:03 2015, ronaldxs wrote​:

On Sat May 11 13​:48​:34 2013, FROGGS.de wrote​:

TimToady​: yes, comparisons should return failure, not automatically
thrown an exception.

It throws an appropriate exception now. I think if a qualified
person
looked at this ticket they could close it.

Ron

Note that the sample code needs to be formatted thusly​:

my Int $x; if $x <=0 { say 'cmp OK' }
Invocant requires a 'Int' instance, but a type object was passed. Did
you forget a .new?

This seems to jibe with expectations. Added tests to S03-
operators/misc.t .... but a nearly identical test for Str doesn't fail
the same way. Test todo'd, needs some work.

As far as I understand, the current implementation does not match the design
docs. Even for the case tested in S03-operators/misc.t the Exception is thrown
immediately -- instead of being returned as a Failure.

My -- maybe naive -- idea would be to add appropriate multi candidates for
all the comparison operators. For example for infix​:<gt>​:

  diff --git a/src/core/Stringy.pm b/src/core/Stringy.pm
  index f8e2279..3364b6f 100644
  --- a/src/core/Stringy.pm
  +++ b/src/core/Stringy.pm
  @​@​ -47,7 +47,13 @​@​ multi sub infix​:<le>(\a, \b) { a.Stringy le b.Stringy }

  proto sub infix​:<gt>(Mu $?, Mu $?) is pure { * }
  multi sub infix​:<gt>($x?) { Bool​::True }
  -multi sub infix​:<gt>(\a, \b) { a.Stringy gt b.Stringy }
  +multi sub infix​:<gt>(Mu​:U, \a) {
  + Failure.new(X​::AdHoc.new(​:payload("failure 'cuz 1st argument of comparison is undefined")))
  +}
  +multi sub infix​:<gt>(Mu​:D \a, Mu​:U) {
  + Failure.new(X​::AdHoc.new(​:payload("failure 'cuz 2nd argument of comparison is undefined")))
  +}
  +multi sub infix​:<gt>(Mu​:D \a, Mu​:D \b) { a.Stringy gt b.Stringy }
 
  proto sub infix​:<ge>(Mu $?, Mu $?) is pure { * }
  multi sub infix​:<ge>($x?) { Bool​::True }

Maybe someone qualified can comment on this idea? I'd be willing to work on the
eventual implementation.

Christian

@p6rt
Copy link
Author

p6rt commented Oct 25, 2015

From @usev6

Oh, and this comment fomr RT
118865 is related​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=118865#txn-1360097

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 25, 2015

From @usev6

Oh, and this comment fomr RT
118865 is related​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=118865#txn-1360097

@p6rt p6rt closed this as completed Apr 7, 2016
@p6rt
Copy link
Author

p6rt commented Apr 7, 2016

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

@p6rt p6rt added the spec 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