Project

General

Profile

Actions

Bug #2134

closed

Inspect Output for Rational and Complex

Added by runpaint (Run Paint Run Run) over 14 years ago. Updated almost 13 years ago.

Status:
Rejected
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-09-11) [i686-linux]
Backport:
[ruby-core:25715]

Description

=begin
The inspect output of both Rational and Complex does not eval to the original number:

Rational(3,5).inspect
=> "(3/5)"
Complex(3,5).inspect
=> "(3+5i)"

In [ruby-core:23856] matz explained that the Rational output, at least, is an intentional change "in preparation for Rational literals, which is planned for the future." Then, in [ruby-core:24731], matz wrote that he was no longer considering literals for imaginary numbers. I'm unsure what if any connection these two statements have.

That many objects with a literal syntax produce #inspect output is eval'able to the same object is a particularly useful characteristic, especially for code generation when you don't want Marshal's obfuscation. The changes in question prevent Complex and Rational being serialised in this fashion. In fact, in Rational's case the breakage is more subtle because the #inspect output is valid syntax, so integer division is performed silently:

eval Rational(7,2).inspect
=> 3

I suppose I have two questions:

  1. Are Rational and Complex literals still planned? (If so, could we open a feature ticket to track the progress?)
  2. Is it necessary that their #inspect output is changed preemptively?
    =end
Actions #1

Updated by tadf (tadayoshi funaba) over 14 years ago

=begin
this is not a bug report.
this is not a matter for rational and complex.
close by yourself.

i believe inspect is for debug.
to eval any ouput of inspect is bad manner.

$ ./ruby -e 'p 0.0/0'
NaN
$ ./ruby -e 'p eval("NaN")'
-e:1:in `eval': uninitialized constant NaN (NameError)

$ ./ruby -e 'p 1.0/0'
Infinity
$ ./ruby -e 'p eval("Infinity..Infinity")'
-e:1:in `eval': uninitialized constant Infinity (NameError)

String#dump is one of what you want.

=end

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 14 years ago

  • Status changed from Open to Assigned
  • Assignee set to tadf (tadayoshi funaba)

=begin

=end

Actions #3

Updated by runpaint (Run Paint Run Run) over 14 years ago

=begin

this is not a bug report.
this is not a matter for rational and complex.
close by yourself.

It was not my intention to cause offense or annoyance... :-/ In my experience the BTS is the most efficient and expedient way to seek clarification for issues concerning trunk development. If there's a preferred alternative, I'd appreciate a pointer. In any case, I can't close tickets.

In case I was simply unclear: Rational#inspect and Complex#inspect both exhibited this useful property previously. The change was predicated on the introduction of rational/complex literals. If said literals are still planned, this can be regarded as a request for confirmation and a tracking ticket, along with consideration of returning to the previous behavior in the interim. If they are not planned it can be regarded as a request for reconsidering the change in light of its premise being invalidated.
=end

Actions #4

Updated by tadf (tadayoshi funaba) over 14 years ago

  • Status changed from Assigned to Rejected

=begin
i don't know why we should track your questions here.
why not post them to list or forum?
anyway this is not a bug.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0