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/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/