<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Questions without answers in Protocols</title>
<link>https://ask.clojure.org/index.php/unanswered/clojure/protocols</link>
<description></description>
<item>
<title>Hypergraphs, via protocols, perhaps extending loom?</title>
<link>https://ask.clojure.org/index.php/13444/hypergraphs-via-protocols-perhaps-extending-loom</link>
<description>&lt;p&gt;I am exploring clojure implementations of hypergraphs (edges can join &amp;gt; 2 nodes)?  i've used &lt;a rel=&quot;nofollow&quot; href=&quot;https://cljdoc.org/d/aysylu/loom&quot;&gt;loom&lt;/a&gt;  for graphs, and imagine trying to extend it somehow.  &lt;/p&gt;
&lt;p&gt;either with loom or without, any suggestions how to use PROTOCOLS for these definitions?&lt;/p&gt;
&lt;p&gt;thanks for any suggestions.  - RIk&lt;/p&gt;
</description>
<category>Protocols</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/13444/hypergraphs-via-protocols-perhaps-extending-loom</guid>
<pubDate>Thu, 09 Nov 2023 02:41:39 +0000</pubDate>
</item>
<item>
<title>Protocol dispatch via interfaces is nondeterministic</title>
<link>https://ask.clojure.org/index.php/11075/protocol-dispatch-via-interfaces-is-nondeterministic</link>
<description>&lt;p&gt;If an object is an instance of multiple (unrelated) interfaces that each extend a protocol, the dispatched method will be chosen at random.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(defn reproduce []
  (eval 
    (list 'do
          (list 'ns (gensym))
          '(do (definterface A)
               (definterface B)

               (defprotocol P
                 (a [this]))

               (extend-protocol P
                 A
                 (a [this] :a)
                 B
                 (a [this] :b))
               (a (reify A B))))))

(frequencies
  (repeatedly 100 reproduce))
;=&amp;gt; {:b 52, :a 48}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;One solution is to sort interfaces by name before choosing the implementation, so at least the nondeterminism is eliminated. We could go further and also print a warning in this case.&lt;/p&gt;
&lt;p&gt;Logged as: &lt;a rel=&quot;nofollow&quot; href=&quot;https://clojure.atlassian.net/browse/CLJ-2656&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2656&lt;/a&gt;&lt;/p&gt;
</description>
<category>Protocols</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/11075/protocol-dispatch-via-interfaces-is-nondeterministic</guid>
<pubDate>Tue, 21 Sep 2021 19:25:07 +0000</pubDate>
</item>
</channel>
</rss>