ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:92540] [Ruby trunk Feature#15824] respond_to pattern for pattern match
       [not found] <redmine.issue-15824.20190505000045@ruby-lang.org>
@ 2019-05-05  0:00 ` fukajun.shark
  2019-05-05 15:32 ` [ruby-core:92552] " shevegen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: fukajun.shark @ 2019-05-05  0:00 UTC (permalink / raw)
  To: ruby-core

Issue #15824 has been reported by fukajun (Jun Fukaya).

----------------------------------------
Feature #15824: respond_to pattern for pattern match
https://bugs.ruby-lang.org/issues/15824

* Author: fukajun (Jun Fukaya)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
rubyに追加されそうなパターンマッチの機能について...
Interger, Array など constantを書くことで、オブジェクトのクラスにマッチングさせる機能があるのを拝見しました。
duck typingを確認するようなパターンマッチがかけるとrubyらしいのではないかと思ってこちらに書いてみることにしました。

respond_to pattern

```ruby
class Runner
  def run
  end

  def stop
  end
end

runner = Runner.new
case runner
in .run & .stop
  :reachable
in .start & .stop
  :unreachable
end 
```



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

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

* [ruby-core:92552] [Ruby trunk Feature#15824] respond_to pattern for pattern match
       [not found] <redmine.issue-15824.20190505000045@ruby-lang.org>
  2019-05-05  0:00 ` [ruby-core:92540] [Ruby trunk Feature#15824] respond_to pattern for pattern match fukajun.shark
@ 2019-05-05 15:32 ` shevegen
  2019-05-22  8:57 ` [ruby-core:92777] " matz
  2019-10-06  7:56 ` [ruby-core:95243] [Ruby master " s.wanabe
  3 siblings, 0 replies; 4+ messages in thread
From: shevegen @ 2019-05-05 15:32 UTC (permalink / raw)
  To: ruby-core

Issue #15824 has been updated by shevegen (Robert A. Heiler).


I don't want to comment so much on the issue as such, but I would like to point
out that it may be a better idea to start with a new idea not on highest
complexity. I am not sure if everyone fully understood pattern matching yet so
in my personal opinion it may be better to see how pattern matching is used
before making it more complex (including syntactic changes). But that's just
my opinion, anyway; some of the syntax appears to become no longer recognizable
ruby (to me).

----------------------------------------
Feature #15824: respond_to pattern for pattern match
https://bugs.ruby-lang.org/issues/15824#change-77919

* Author: fukajun (Jun Fukaya)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
rubyに追加されそうなパターンマッチの機能について...
Interger, Array など constantを書くことで、オブジェクトのクラスにマッチングさせる機能があるのを拝見しました。
duck typingを確認するようなパターンマッチがかけるとrubyらしいのではないかと思ってこちらに書いてみることにしました。

respond_to pattern

```ruby
class Runner
  def run
  end

  def stop
  end
end

runner = Runner.new
case runner
in .run & .stop
  :reachable
in .start & .stop
  :unreachable
end 
```



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

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

* [ruby-core:92777] [Ruby trunk Feature#15824] respond_to pattern for pattern match
       [not found] <redmine.issue-15824.20190505000045@ruby-lang.org>
  2019-05-05  0:00 ` [ruby-core:92540] [Ruby trunk Feature#15824] respond_to pattern for pattern match fukajun.shark
  2019-05-05 15:32 ` [ruby-core:92552] " shevegen
@ 2019-05-22  8:57 ` matz
  2019-10-06  7:56 ` [ruby-core:95243] [Ruby master " s.wanabe
  3 siblings, 0 replies; 4+ messages in thread
From: matz @ 2019-05-22  8:57 UTC (permalink / raw)
  To: ruby-core

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


Interesting idea. We need to investigate the idea further.

Matz.


----------------------------------------
Feature #15824: respond_to pattern for pattern match
https://bugs.ruby-lang.org/issues/15824#change-78142

* Author: fukajun (Jun Fukaya)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
rubyに追加されそうなパターンマッチの機能について...
Interger, Array など constantを書くことで、オブジェクトのクラスにマッチングさせる機能があるのを拝見しました。
duck typingを確認するようなパターンマッチがかけるとrubyらしいのではないかと思ってこちらに書いてみることにしました。

respond_to pattern

```ruby
class Runner
  def run
  end

  def stop
  end
end

runner = Runner.new
case runner
in .run & .stop
  :reachable
in .start & .stop
  :unreachable
end 
```



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

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

* [ruby-core:95243] [Ruby master Feature#15824] respond_to pattern for pattern match
       [not found] <redmine.issue-15824.20190505000045@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-05-22  8:57 ` [ruby-core:92777] " matz
@ 2019-10-06  7:56 ` s.wanabe
  3 siblings, 0 replies; 4+ messages in thread
From: s.wanabe @ 2019-10-06  7:56 UTC (permalink / raw)
  To: ruby-core

Issue #15824 has been updated by wanabe (_ wanabe).


The implementation can be very simple.
(I don't know whether `NODE_METHREF` is suitable.)

```diff
diff --git a/compile.c b/compile.c
index 7a88f81daa..f6eafb0ac2 100644
--- a/compile.c
+++ b/compile.c
@@ -5888,6 +5888,11 @@ iseq_compile_pattern_each(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *c
         ADD_LABEL(ret, fin);
         break;
       }
+      case NODE_METHREF: {
+        ADD_INSN1(ret, line, putobject, ID2SYM(node->nd_mid));
+        ADD_SEND(ret, line, idRespond_to, INT2FIX(1));
+        break;
+      }
       default:
         UNKNOWN_NODE("NODE_IN", node, COMPILE_NG);
     }
diff --git a/parse.y b/parse.y
index 287704e14f..dd305479f5 100644
--- a/parse.y
+++ b/parse.y
@@ -3904,6 +3904,10 @@ p_expr_basic     : p_value
                    {
                        $$ = $2;
                    }
+                | '.' operation2
+                    {
+                       $$ = NEW_METHREF(Qundef, $2, &@$);
+                    }
                ;
 
 p_args         : p_expr
```

By the way, missing "& pattern" seems to be intended. see [ruby-core:88036] https://bugs.ruby-lang.org/issues/14912#note-7 .



----------------------------------------
Feature #15824: respond_to pattern for pattern match
https://bugs.ruby-lang.org/issues/15824#change-81917

* Author: fukajun (Jun Fukaya)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
rubyに追加されそうなパターンマッチの機能について...
Interger, Array など constantを書くことで、オブジェクトのクラスにマッチングさせる機能があるのを拝見しました。
duck typingを確認するようなパターンマッチがかけるとrubyらしいのではないかと思ってこちらに書いてみることにしました。

respond_to pattern

```ruby
class Runner
  def run
  end

  def stop
  end
end

runner = Runner.new
case runner
in .run & .stop
  :reachable
in .start & .stop
  :unreachable
end 
```



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

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

end of thread, other threads:[~2019-10-06  7:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15824.20190505000045@ruby-lang.org>
2019-05-05  0:00 ` [ruby-core:92540] [Ruby trunk Feature#15824] respond_to pattern for pattern match fukajun.shark
2019-05-05 15:32 ` [ruby-core:92552] " shevegen
2019-05-22  8:57 ` [ruby-core:92777] " matz
2019-10-06  7:56 ` [ruby-core:95243] [Ruby master " s.wanabe

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 read-only IMAP folder(s) and NNTP newsgroup(s).