Forum: Ruby-core [ruby-trunk - Feature #8430][Open] Rational number literal

7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-05-21 15:31
(Received via mailing list)
Issue #8430 has been reported by mrkn (Kenta Murata).

----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-05-21 15:44
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).


I updated the patch for fixing negative rational numbers:
https://github.com/mrkn/ruby/commit/b16f4da893c1cb...
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39466

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-05-22 04:08
(Received via mailing list)
Issue #8430 has been updated by nobu (Nobuyoshi Nakada).


Shouldn't tDIV2 be only if IS_SPCARG(c)?
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39471

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
6789224081b49822eb70f6740beb5ed5?d=identicon&s=25 knu (Akinori MUSHA) (Guest)
on 2013-05-22 04:49
(Received via mailing list)
Issue #8430 has been updated by knu (Akinori MUSHA).


I think it should be added as an operator rather than a literal
notation.

A literal should not look like an expression, or it will fail you when
you find out you have to give up the // notation in order to constify a
numerator and/or a denominator of a rational literal like that.

Also, I guess runtime cost would not change much if it were introduced
as operator.
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39472

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
F736999f7c1b7a87a100faa112bbc0f3?d=identicon&s=25 charliesome (Charlie Somerville) (Guest)
on 2013-05-22 05:29
(Received via mailing list)
Issue #8430 has been updated by charliesome (Charlie Somerville).


> Also, I guess runtime cost would not change much if it were introduced as
operator.

Rational is immutable, so if it it was introduced as a literal, the same
Rational instance could be re-used, similar to how symbols and fixnums
work.

If // was introduced as an operator, a new object would need to be
allocated each time, similar to strings.
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39473

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
3df767279ce7d81db0a5bb30f5136863?d=identicon&s=25 Matthew Kerwin (mattyk)
on 2013-05-22 06:45
(Received via mailing list)
Issue #8430 has been updated by phluid61 (Matthew Kerwin).


charliesome (Charlie Somerville) wrote:
> > Also, I guess runtime cost would not change much if it were introduced as
operator.
>
> Rational is immutable, so if it it was introduced as a literal, the same
Rational instance could be re-used, similar to how symbols and fixnums work.
>
> If // was introduced as an operator, a new object would need to be allocated
each time, similar to strings.

At the risk of asking something stupid, could it be both?  I'm thinking
of unary minus / literal negative number.  (Assuming there's such a
thing in Ruby as a literal negative (?))

----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39476

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-05-22 10:16
(Received via mailing list)
Issue #8430 has been updated by nobu (Nobuyoshi Nakada).


I also prefer an operator.

https://github.com/nobu/ruby/commit/7ff6073d703069...
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39481

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-05-22 10:22
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).


knu (Akinori MUSHA) wrote:
> I think it should be added as an operator rather than a literal notation.
>
> A literal should not look like an expression, or it will fail you when you find
out you have to give up the // notation in order to constify a numerator and/or 
a
denominator of a rational literal like that.

I made another implementation of the rational number literal implemented
in token-level.
The implementation is available in
https://github.com/mrkn/ruby/commit/f0bf41b6593866...
Whitespaces around of // aren't permitted in this implementation.
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39482

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-05-22 10:25
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).


nobu (Nobuyoshi Nakada) wrote:
> I also prefer an operator.
>
> https://github.com/nobu/ruby/commit/7ff6073d703069...

Pretty nice!

I love this if introducing // as a operator is accepted.

----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39483

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-05-29 02:48
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).


Yesterday I ask matz about merging it to trunk, he said it is ok with
experimental mark like refinements.

And I confirmed that nobu's quo-operator doesn't conflict with empty
regexps:

  $ .prefix/bin/ruby -e 'f=1; i=2; p(f //i)'
  (1/2)

  $ .prefix/bin/ruby -e 'def f(a); p a; end; i=2; p(f //i)'
  //i
  //i
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39549

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-05-29 10:37
(Received via mailing list)
Issue #8430 has been updated by nobu (Nobuyoshi Nakada).


It does change the interpretation of the following code

  foo.split //
  bar

It is "foo.split(//); bar" currently, but it would be
"foo.split.//(bar)" with the patch.

Of course it's possible to address it by heuristically, but I wonder if
it's good or worth to do.
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39555

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
3df767279ce7d81db0a5bb30f5136863?d=identicon&s=25 Matthew Kerwin (mattyk)
on 2013-05-30 05:17
(Received via mailing list)
Issue #8430 has been updated by phluid61 (Matthew Kerwin).


=begin
nobu (Nobuyoshi Nakada) wrote:

> Of course it's possible to address it heuristically, but I wonder if it's good
or worth to do.

How about a different symbol?  Since (({:})) is the standard
mathematical symbol for ratio, why not define (({[+-]?\d+:\d+})) as an
immediate Rational, and/or (({:})) as an operator?

As an operator it conflicts with short symbol/hash syntax only in the
case that the left-hand operand is a tIDENTIFIER (like local
variable/function) and there is no whitespace before the (({:})).  Not
sure if that's better or worse than the empty regexp conflict.
=end
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39564

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-05-30 15:35
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).


phluid61 (Matthew Kerwin) wrote:
> How about a different symbol?  Since (({:})) is the standard mathematical symbol
for ratio, why not define (({[+-]?\d+:\d+})) as an immediate Rational, and/or
(({:})) as an operator?

It collides to the conditional operator, ?:, for example:

   expr ? 1:2

As I discussed with matz and akr today, the token-level implementation
of // doesn't introduce incompatibility, so it can be introduced safely.
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39568

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
888ca72b6dae7501346d3c38493a9e96?d=identicon&s=25 rohansoni619 (Rohan Soni) (Guest)
on 2013-06-08 07:25
(Received via mailing list)
Issue #8430 has been updated by rohansoni619 (Rohan Soni).


different symbol changes the interpretation.
http://www.jaro.in/international-MBA-1-year.html
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-39786

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-06-23 20:39
(Received via mailing list)
Issue #8430 has been updated by headius (Charles Nutter).


Not sure if the debate still rages, but something that keeps the
numerator and denominator together in a single "literal" seems better to
me. Why not add another % literal?

%R{1,2}

There's no other literals that are produced via a magic infix operator,
and it seems confusing to me.
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40100

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
3df767279ce7d81db0a5bb30f5136863?d=identicon&s=25 Matthew Kerwin (mattyk)
on 2013-06-24 01:52
(Received via mailing list)
Issue #8430 has been updated by phluid61 (Matthew Kerwin).


headius (Charles Nutter) wrote:
> Not sure if the debate still rages, but something that keeps the numerator and
denominator together in a single "literal" seems better to me. Why not add 
another
% literal?
>
> %R{1,2}
>
> There's no other literals that are produced via a magic infix operator, and it
seems confusing to me.

+1 this seems to introduce the least potential for confusion and
backwards-incompatibility.  Question: at what place(s) would a negative
sign be allowed? %R{-1,2}, %R{1,-2}, etc.?

----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40105

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-06-24 17:26
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).


> %R{1,2}

It isn't similar to a fraction.

----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40118

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-06-24 22:45
(Received via mailing list)
Issue #8430 has been updated by headius (Charles Nutter).


mrkn (Kenta Murata) wrote:
> > %R{1,2}
>
> It isn't similar to a fraction.

Does it have to be?

How about %R{1/2} then?
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40120

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2013-06-24 22:49
(Received via mailing list)
Issue #8430 has been updated by headius (Charles Nutter).


phluid61 (Matthew Kerwin) wrote:
> headius (Charles Nutter) wrote:
> > %R{1,2}
>
> +1 this seems to introduce the least potential for confusion and
backwards-incompatibility.  Question: at what place(s) would a negative sign be
allowed? %R{-1,2}, %R{1,-2}, etc.?

I suppose anywhere you can pass them to Rational's constructor...so both
numerator and denominator.

If the slash syntax is more to @mrkn's liking, these examples would be
%R{-1/2} and %R{1/-2}.

Note that since Rational() takes a string, the slashy %R format fits
well the other % formats, in that % formats wrap something string-like
that's then processed into a more specific data type, cacheable as a
literal object in many cases.

I really do not like the // magic infix literal format.
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40121

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-06-28 03:41
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).


headius (Charles Nutter) wrote:
> If the slash syntax is more to @mrkn's liking, these examples would be %R{-1/2}
and %R{1/-2}.

I don't hate this form. It is better than %R{1,2}.
But I think 1//2 looks like a fraction than %R{1/2}.

----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40184

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
3df767279ce7d81db0a5bb30f5136863?d=identicon&s=25 Matthew Kerwin (mattyk)
on 2013-06-28 04:03
(Received via mailing list)
Issue #8430 has been updated by phluid61 (Matthew Kerwin).


mrkn (Kenta Murata) wrote:
> headius (Charles Nutter) wrote:
> > If the slash syntax is more to @mrkn's liking, these examples would be
%R{-1/2} and %R{1/-2}.
>
> I don't hate this form. It is better than %R{1,2}.
> But I think 1//2 looks like a fraction than %R{1/2}.

Slightly bike-shedding, but I have issues with // as an operator.  For
one, it immediately screams "comment" at me, even though ruby comments
use #, simply because so many other languages use it.  Then after that,
I wonder at the relationship between / and // when compared to * and **
(i.e. is // meant to mean some sort of multi-phased divide, or a
logarithm?)

The reason I particularly like %R{1/2} is that it contains the existing
division operator, 1/2, without any modification, so at a glance you can
see that 1/2 and %R{1/2} are in some way equivalent, but the %R{} around
it adds some flavourful difference.

The %R format also lends itself to interpolation, if such is deemed to
be useful, e.g. %R(-#{foo}/2), which could arguably be more or less
useful than variable operands.
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40185

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
0ec4920185b657a03edf01fff96b4e9b?d=identicon&s=25 matz (Yukihiro Matsumoto) (Guest)
on 2013-07-27 09:16
(Received via mailing list)
Issue #8430 has been updated by matz (Yukihiro Matsumoto).


The final idea was "1r" to be "Rational(1,1)".  We also accept the idea
of "1i" as "Complex(0,1)".

Matz.

----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40713

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-07-27 09:29
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).


matz (Yukihiro Matsumoto) wrote:
> The final idea was "1r" to be "Rational(1,1)".  We also accept the idea of "1i"
as "Complex(0,1)".

Additionaly them, "1.2r" as "Rational(12, 10)" is also accepted.
But the exponential form with "r" suffix like "1e-5r" is not accepted
because it can make us confusing.
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40714

Author: mrkn (Kenta Murata)
Status: Open
Priority: Normal
Assignee: matz (Yukihiro Matsumoto)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-07-27 17:09
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).

Status changed from Open to Assigned
Assignee changed from matz (Yukihiro Matsumoto) to mrkn (Kenta Murata)


----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40717

Author: mrkn (Kenta Murata)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 takuto_h (Takuto Hayashi) (Guest)
on 2013-08-01 09:53
(Received via mailing list)
Issue #8430 has been updated by takuto_h (Takuto Hayashi).

File ratio_lit.patch added

Hello.
I wrote a patch for the rational number literal and recognized that a
part of the proposed feature is confusable.

If we accept "1.2r" as "Rational(12, 10)":
    1/3r      #=> (1/3)
    0.4/1.2r  #=> 0.33333333333333337

I think this feature's point is that "1/3r" can be seen as "1/3"
followed by "r",
so it can make us confusing that "0.4/1.2" followed by "r" is not a
rational number.

The attached file is a patch which accept "3r" and doesn't accept
"1.2r".
The implementation is also available at:
https://github.com/takuto-h/ruby/commit/6827688ee6...

Thank you.

----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40791

Author: mrkn (Kenta Murata)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
F24ff61beb80aa5f13371aa22a35619c?d=identicon&s=25 mame (Yusuke Endoh) (Guest)
on 2013-08-01 15:06
(Received via mailing list)
Issue #8430 has been updated by mame (Yusuke Endoh).


takuto_h (Takuto Hayashi) wrote:
> Hello.
> I wrote a patch for the rational number literal

Great.

> and recognized that a part of the proposed feature is confusable.
>
> If we accept "1.2r" as "Rational(12, 10)":
>     1/3r      #=> (1/3)
>     0.4/1.2r  #=> 0.33333333333333337
>
> I think this feature's point is that "1/3r" can be seen as "1/3" followed by
"r",
> so it can make us confusing that "0.4/1.2" followed by "r" is not a rational
number.

IMO, it does not matter because we don't usually write a rational whose
numerator and denominator are decimal.
Also, it is very clear and reasonable what happens.

--
Yusuke Endoh <mame@tsg.ne.jp>
----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40797

Author: mrkn (Kenta Murata)
Status: Assigned
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
7cca11c5257fda526eeb4b1ada28f904?d=identicon&s=25 mrkn (Kenta Murata) (Guest)
on 2013-08-01 17:20
(Received via mailing list)
Issue #8430 has been updated by mrkn (Kenta Murata).


takuto_h (Takuto Hayashi) wrote:
> Hello.
> I wrote a patch for the rational number literal and recognized that a part of
the proposed feature is confusable.

Thank you. But I'd already have a patch made by me on the last Sunday.
Although I've commited the changes based on my patch,
I really appreciate your contribution for this issue.

----------------------------------------
Feature #8430: Rational number literal
https://bugs.ruby-lang.org/issues/8430#change-40800

Author: mrkn (Kenta Murata)
Status: Closed
Priority: Normal
Assignee: mrkn (Kenta Murata)
Category: core
Target version: current: 2.1.0


I would like to propose a new literal syntax for rational numbers.
The implementation is available in my github repository:
https://github.com/mrkn/ruby/commit/8ca0c9a53593e5...

This patch implements a notation that consists of an integer, "//", and
another integer, in a row.
The first integer is the numerator, and the second is the denominator.
Whitespaces are permitted between them.

For example:
    1 // 2 == Rational(1, 2)
    1 // 1 == Rational(1, 1)
    0 // 1 == Rational(0, 1)

"0 // 0" occurs syntax error.

I think this new syntax isn't conflict with an empty regexp
because this implementation doesn't treat // as a binary operator.
05ba106041716c821d3ab34bd60ea220?d=identicon&s=25 David MacMahon (Guest)
on 2013-08-01 18:54
(Received via mailing list)
On Aug 1, 2013, at 12:53 AM, takuto_h (Takuto Hayashi) wrote:

> If we accept "1.2r" as "Rational(12, 10)":
>    1/3r      #=> (1/3)
>    0.4/1.2r  #=> 0.33333333333333337
>
> I think this feature's point is that "1/3r" can be seen as "1/3" followed by
"r",
> so it can make us confusing that "0.4/1.2" followed by "r" is not a rational
number.

I haven't looked at the implementation, but my understanding was that
1/3r was seen as 1 divided by Rational(3,1).  With that interpretation,
I think 0.4/1.2r is not confusing: 0.4/1.2r is a Float (i.e. 0.4)
divided by a Rational (i.e. Rational(12,10) or 1.2r).  Float divided by
Rational gives Float.  To end up with a Rational result, use 0.4r/1.2r.

> The attached file is a patch which accept "3r" and doesn't accept "1.2r".

I very much like the idea of "1.2r", let's please keep accepting 1.2r.

Thanks,
Dave
This topic is locked and can not be replied to.