Alternative idea: If Ruby has a feature like: ~~~ ruby x = x.left_variable? # => true y = x.left_variable? # => false ~~~ then inplace operation is possible without redefinition of `+=`. masa16 (Masahiro Tanaka)
I think it is enough to change the meaning of ~~~ ruby x += a ~~~ to ~~~ ruby if x.respond_to?(:'+=') x.send(:'+=',a) else x = x + a end ~~~ Matz rejected this in http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/...masa16 (Masahiro Tanaka)
nobu (Nobuyoshi Nakada) wrote: > It seems a different story from `+=`. I am sorry for getting off the point, but I wanted to say that `add!` method does not solve the problem. > ... This cannot be a solution because both inplace a...masa16 (Masahiro Tanaka)
Former NArray had `add!` method, but it results in a confused result. ~~~ ruby require 'narray' a = NArray.int(2,2).indgen! a[1,true] += 10 p a # => NArray.int(2,2): # [ [ 0, 11 ], # [ 2, 13 ] ] a = NArray.int(2,...masa16 (Masahiro Tanaka)
System: CentOS Linux release 7.3.1611 (Core) Kernel: 3.10.0-514.2.2.el7.x86_64 GCC: gcc version 4.8.5 20150623 (Red Hat 4.8.5-11) (GCC) The following script crushes with ruby 2.4.0, 2.3.3 and 2.2.6. ~~~ ruby 100.times do |i| ...masa16 (Masahiro Tanaka)
2011/9/17 Masahiro TANAKA <masa16.tanaka@gmail.com>: > --- numeric.c (revision 33288) > ... This patch involves a problem: a=(1.0..1-2e-16).step(1.0).to_a; p a #=> [1.0] ; should be [] The following patch would be better. --- numeri...masa16 (Masahiro Tanaka)
I have not been watching ruby-core, but let me give a comment for this issue. I proposed Numeric#step algorithm for Float in [ruby-dev:20177], but that was only for the include_end-case. > (1...6.3).step.to_a # => [1.0, 2.0, 3.0, 4.0, ...masa16 (Masahiro Tanaka)