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/f0bf41b6593866b82ab0068e6a66ce7c12748aec
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/8ca0c9a53593e55d67f509fc403df616e2276e3a

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.



-- 
http://bugs.ruby-lang.org/