Project

General

Profile

Actions

Feature #17769

closed

Proposal: numeric coefficient syntax

Added by mrkn (Kenta Murata) over 3 years ago. Updated over 3 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:103140]
Tags:

Description

When we write a mathematical equation, we often omit a multiplication operator between a coefficient and a variable like 2x.
I guess this convention can be useful in computer programming. Practically, Julia employs this notation:

julia> 2pi
6.283185307179586

julia> x = 3
3

julia> 2x
6

julia> pi
π = 3.1415926535897...

julia> 2pi
6.283185307179586

I wrote a proof-of-concept patch to introduce this notation in Ruby.
We can write the following with this patch:

irb(main):001:0> x = 3
=> 3
irb(main):002:0> 2x
=> 6
irb(main):003:0> def pi = Math::PI
=> :pi
irb(main):004:0> 2pi
=> 6.283185307179586

Files

num_coeff.patch (1.03 KB) num_coeff.patch mrkn (Kenta Murata), 04/01/2021 03:25 AM
Actions #1

Updated by mame (Yusuke Endoh) over 3 years ago

  • Tags set to joke

Updated by matz (Yukihiro Matsumoto) over 3 years ago

i = 10
p 2i # => 20 or Complex(0,2)?

Matz.

Updated by mrkn (Kenta Murata) over 3 years ago

2i is an imaginary number literal so it is Complex(0, 2).

Actions #4

Updated by mrkn (Kenta Murata) over 3 years ago

  • File deleted (num_coeff.patch)

Updated by mrkn (Kenta Murata) over 3 years ago

  • File num_coeff.patch added

I replaced the attached patch with changes to accept not only 2x but also 2(x + 1).

Updated by mrkn (Kenta Murata) over 3 years ago

Replace the patch with refactoring.

Actions #7

Updated by mrkn (Kenta Murata) over 3 years ago

  • File deleted (num_coeff.patch)
Actions #8

Updated by mrkn (Kenta Murata) over 3 years ago

  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0