ruby-dev (Japanese) list archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-dev:51170] [Ruby master Feature#18626] 注釈付き代入演算子 ()= の提案
@ 2022-03-12  1:47 takiuchi (Genki Takiuchi)
  2022-03-12  7:59 ` [ruby-dev:51171] " sawa (Tsuyoshi Sawada)
  2022-03-20 14:24 ` [ruby-dev:51174] " matz (Yukihiro Matsumoto)
  0 siblings, 2 replies; 3+ messages in thread
From: takiuchi (Genki Takiuchi) @ 2022-03-12  1:47 UTC (permalink / raw)
  To: ruby-dev

Issue #18626 has been reported by takiuchi (Genki Takiuchi).

----------------------------------------
Feature #18626: 注釈付き代入演算子 ()= の提案
https://bugs.ruby-lang.org/issues/18626

* Author: takiuchi (Genki Takiuchi)
* Status: Open
* Priority: Normal
----------------------------------------
型制約を実現するために以下のような注釈付き代入演算子を提案します。

```
class Object
  def self.()= (what)
    what.is_a? self or raise TypeRestrictionError
  end
end

age (Fixnum) = 30

def add(a(Numeric), b(Numeric))
  a + b
end
add 1, "2" # raises TypeRestrictionError
```

左辺値の後に`(...)` が続いた場合に`()`内の値に対して`()=`演算子を呼び出します。
Rubyはメソッドの返り値が左辺値になることは無いので既存の文法とは衝突しないかなと。

以下のようなenum的な制約も便利だと思います。

```
class Array
  def ()= (what)
    self.include? what
  end
end

flag([1,2,3]) = 3
```

いかがでしょうか。



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-dev:51171] [Ruby master Feature#18626] 注釈付き代入演算子 ()= の提案
  2022-03-12  1:47 [ruby-dev:51170] [Ruby master Feature#18626] 注釈付き代入演算子 ()= の提案 takiuchi (Genki Takiuchi)
@ 2022-03-12  7:59 ` sawa (Tsuyoshi Sawada)
  2022-03-20 14:24 ` [ruby-dev:51174] " matz (Yukihiro Matsumoto)
  1 sibling, 0 replies; 3+ messages in thread
From: sawa (Tsuyoshi Sawada) @ 2022-03-12  7:59 UTC (permalink / raw)
  To: ruby-dev

Issue #18626 has been updated by sawa (Tsuyoshi Sawada).


Related to #18603

----------------------------------------
Feature #18626: 注釈付き代入演算子 ()= の提案
https://bugs.ruby-lang.org/issues/18626#change-96802

* Author: takiuchi (Genki Takiuchi)
* Status: Open
* Priority: Normal
----------------------------------------
型制約を実現するために以下のような注釈付き代入演算子を提案します。

```
class Object
  def self.()= (what)
    what.is_a? self or raise TypeRestrictionError
  end
end

age (Fixnum) = 30

def add(a(Numeric), b(Numeric))
  a + b
end
add 1, "2" # raises TypeRestrictionError
```

左辺値の後に`(...)` が続いた場合に`()`内の値に対して`()=`演算子を呼び出します。
Rubyはメソッドの返り値が左辺値になることは無いので既存の文法とは衝突しないかなと。

以下のようなenum的な制約も便利だと思います。

```
class Array
  def ()= (what)
    self.include? what
  end
end

flag([1,2,3]) = 3
```

いかがでしょうか。



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [ruby-dev:51174] [Ruby master Feature#18626] 注釈付き代入演算子 ()= の提案
  2022-03-12  1:47 [ruby-dev:51170] [Ruby master Feature#18626] 注釈付き代入演算子 ()= の提案 takiuchi (Genki Takiuchi)
  2022-03-12  7:59 ` [ruby-dev:51171] " sawa (Tsuyoshi Sawada)
@ 2022-03-20 14:24 ` matz (Yukihiro Matsumoto)
  1 sibling, 0 replies; 3+ messages in thread
From: matz (Yukihiro Matsumoto) @ 2022-03-20 14:24 UTC (permalink / raw)
  To: ruby-dev

Issue #18626 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected

Very interesting proposal both syntax-wise and semantic-wise. But I have decided that we are not going to introduce any kind of syntax annotation in the language, sorry.

Matz.

文法的にも意味論的にも大変興味深い提案ですが、Ruby言語にいかなる形であれ型宣言や型注釈を導入するつもりはありません。すみません。

まつもと ゆきひろ /:|)


----------------------------------------
Feature #18626: 注釈付き代入演算子 ()= の提案
https://bugs.ruby-lang.org/issues/18626#change-96946

* Author: takiuchi (Genki Takiuchi)
* Status: Rejected
* Priority: Normal
----------------------------------------
型制約を実現するために以下のような注釈付き代入演算子を提案します。

```
class Object
  def self.()= (what)
    what.is_a? self or raise TypeRestrictionError
  end
end

age (Fixnum) = 30

def add(a(Numeric), b(Numeric))
  a + b
end
add 1, "2" # raises TypeRestrictionError
```

左辺値の後に`(...)` が続いた場合に`()`内の値に対して`()=`演算子を呼び出します。
Rubyはメソッドの返り値が左辺値になることは無いので既存の文法とは衝突しないかなと。

以下のようなenum的な制約も便利だと思います。

```
class Array
  def ()= (what)
    self.include? what or raise ValueRestrictionError
  end
end

flag([1,2,3]) = 3
```

いかがでしょうか。



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-03-20 14:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-12  1:47 [ruby-dev:51170] [Ruby master Feature#18626] 注釈付き代入演算子 ()= の提案 takiuchi (Genki Takiuchi)
2022-03-12  7:59 ` [ruby-dev:51171] " sawa (Tsuyoshi Sawada)
2022-03-20 14:24 ` [ruby-dev:51174] " matz (Yukihiro Matsumoto)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).