Project

General

Profile

Actions

Feature #4007

closed

numeric literal syntax sugar

Feature #4007: numeric literal syntax sugar

Added by neleai (Ondrej Bilka) about 15 years ago. Updated almost 8 years ago.

Status:
Rejected
Target version:
[ruby-core:32971]

Description

=begin
Hello
As I looked to C++ extension suffing numeric literals.
My proposal is make . in method call of numeric literal optional so we can for example write
4i instead 4.i
Another application is making Time manipulations more readable like
deadline=Time.now + 2hours

Here is patch
It should be more restrictive to disallow traps like 0xadup
Index: parse.y

--- parse.y (revision 29647)
+++ parse.y (working copy)
@@ -3592,6 +3592,16 @@
$$ = method_arg(dispatch1(fcall, $1), $2);
%*/
}

  •  | numeric tIDENTIFIER opt_paren_args 
  •  { 
  •  /*%%%*/ 
  • 	$$ = NEW_CALL($1, $2, $3); 
  • 	fixpos($$, $1); 
  •  /*% 
  • 	$$ = dispatch3(call, $1, ripper_id2sym('.'), $2); 
  • 	$$ = method_optarg($$, $3); 
  •  %*/ 
  •  } | primary_value '.' operation2 opt_paren_args { /*%%%*/ 

=end

Updated by darix (Marcus Rückert) about 15 years ago Actions #1

=begin
On 2010-10-30 22:25:20 +0900, Ondrej Bilka wrote:

As I looked to C++ extension suffing numeric literals.
My proposal is make . in method call of numeric literal optional so we can for example write
4i instead 4.i
Another application is making Time manipulations more readable like
deadline=Time.now + 2hours

activesupport already gives us stuff like
Time.now + 2.hours

is typing the dot really that much extra work for you?

 darix 

--
openSUSE - SUSE Linux is my linux
openSUSE is good for you
www.opensuse.org

=end

Updated by neleai (Ondrej Bilka) about 15 years ago Actions #2

=begin
On Sat, Oct 30, 2010 at 10:37:16PM +0900, Marcus Rueckert wrote:

On 2010-10-30 22:25:20 +0900, Ondrej Bilka wrote:

As I looked to C++ extension suffing numeric literals.
My proposal is make . in method call of numeric literal optional so we can for example write
4i instead 4.i
Another application is making Time manipulations more readable like
deadline=Time.now + 2hours

activesupport already gives us stuff like
Time.now + 2.hours

is typing the dot really that much extra work for you?
Its matter whats more elegant.

darix 

--
openSUSE - SUSE Linux is my linux
openSUSE is good for you
www.opensuse.org

--

CPU needs recalibration

=end

Updated by naruse (Yui NARUSE) about 15 years ago Actions #3

  • Status changed from Open to Assigned
  • Assignee set to matz (Yukihiro Matsumoto)

=begin

=end

Updated by yhara (Yutaka HARA) about 13 years ago Actions #4 [ruby-core:48240]

  • Description updated (diff)
  • Target version changed from 2.0.0 to 3.0

Updated by mame (Yusuke Endoh) almost 8 years ago Actions #5 [ruby-core:83919]

  • Status changed from Assigned to Rejected

Some suffixes for number literals, such as 4i and 4r, were introduced as a custom syntax. Please reopen if you still want a general framework for number suffixes.

Actions

Also available in: PDF Atom