[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-core
Subject: [ruby-core:86757] [Ruby trunk Feature#14701] If the object is not frozen, I want to be able to redef
From: gotoken () gmail ! com
Date: 2018-04-29 5:50:05
Message-ID: redmine.journal-71710.20180429055004.400acafb79c25012 () ruby-lang ! org
[Download RAW message or body]
Issue #14701 has been updated by gotoken (Kentaro Goto).
Maybe I don't get the point though, if `Numo::NArray#inplace` and `inplace.+` always \
return identical object, `#inplace=` can be define and one can wrote
```
a = Numo::Int32[5, 6]
a.inplace += 1
```
means shorthand for `a.inplace = a.inplace + 1`. This setter `#inplace=` has no \
side-effect because `a.inplace + 1` returns identical to `a.inplace` of LHS by \
assumption.
It also gives same side-effects to `a` for these:
```
a.inplace + 1
```
```
inp = a.inplace
inp += 1
```
By the way, to define similar things with index `#[]=`, `#[]` should be returns a \
view.
----------------------------------------
Feature #14701: If the object is not frozen, I want to be able to redefine the \
compound assignment operator. https://bugs.ruby-lang.org/issues/14701#change-71710
* Author: naitoh (Jun NAITOH)
* Status: Rejected
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
If the object is not frozen, I want to be able to redefine the compound assignment \
operator (e.g. +=, -=, *=, /=, ..etc ).
https://docs.ruby-lang.org/ja/latest/doc/spec=2foperator.html
* Redefinable operator (method)
~~~
| ^ & <=> == === =~ > >= < <= << >>
+ - * / % ** ~ +@ -@ [] []= ` ! != !~
~~~
* use case
~~~
> require 'numo/narray'
> a = Numo::Int32[5, 6]
=> Numo::Int32#shape=[2]
[5, 6]
> a.object_id
=> 70326927544920
> a += 1
=> Numo::Int32#shape=[2]
[6, 7]
> a.object_id
=> 70326927530540
> a.inplace + 1
=> Numo::Int32(view)#shape=[2]
[7, 8]
> a.object_id
=> 70326927530540
~~~
With Numo::NArray, using "inplace" instead of "+=" will update the same object so it \
will be faster.
I want to write "a += 1" instead of "a.inplace + 1".
However, Ruby can not redefine "+=".
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic