<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Clojure Q&amp;A - Recent questions and answers in Multimethods</title>
<link>https://ask.clojure.org/index.php/qa/clojure/multimethods</link>
<description></description>
<item>
<title>Answered: fn? and multimethods</title>
<link>https://ask.clojure.org/index.php/14169/fn-and-multimethods?show=14171#a14171</link>
<description>&lt;p&gt;Almost always, you really want &lt;code&gt;ifn?&lt;/code&gt; - is that what you want here?&lt;/p&gt;
</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/14169/fn-and-multimethods?show=14171#a14171</guid>
<pubDate>Mon, 07 Oct 2024 22:44:06 +0000</pubDate>
</item>
<item>
<title>Answered: Please add dispatch-fn to clojure.core</title>
<link>https://ask.clojure.org/index.php/10261/please-add-dispatch-fn-to-clojure-core?show=11322#a11322</link>
<description>&lt;p&gt;What is the use case for this in ClojureScript and/or why do you want it in Clojure?&lt;/p&gt;
</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10261/please-add-dispatch-fn-to-clojure-core?show=11322#a11322</guid>
<pubDate>Mon, 29 Nov 2021 14:51:22 +0000</pubDate>
</item>
<item>
<title>Answered: Memory leak using the default method of a multimethod</title>
<link>https://ask.clojure.org/index.php/10532/memory-leak-using-the-default-method-of-a-multimethod?show=10533#a10533</link>
<description>&lt;p&gt;I don't know if this is a leak so much as a design assumption that the number of dispatch values is bounded.&lt;/p&gt;
&lt;p&gt;At one time we did not cache the dispatch values resulting in :default case and this made the :default very slow (this was the primary reason multimethods were considered &quot;slow&quot; for a long time). In 1.8, &lt;a rel=&quot;nofollow&quot; href=&quot;http://dev.clojure.org/jira/browse/CLJ-1429&quot;&gt;http://dev.clojure.org/jira/browse/CLJ-1429&lt;/a&gt; changed this and it was a substantial performance boost for a lot of real programs.&lt;/p&gt;
&lt;p&gt;Maybe there is some middle ground, not sure.&lt;/p&gt;
</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10532/memory-leak-using-the-default-method-of-a-multimethod?show=10533#a10533</guid>
<pubDate>Wed, 28 Apr 2021 14:36:47 +0000</pubDate>
</item>
<item>
<title>Answered: Self-Like Pattern Using Multi-Methods</title>
<link>https://ask.clojure.org/index.php/10449/self-like-pattern-using-multi-methods?show=10473#a10473</link>
<description>&lt;p&gt;You could also look at building something on top of clojure.core.match.  Do not feel boxed-in by multimethods!  Or you might be able to get closer to the ideal by writing your own macros to do the dispatching.  One thing to watch out for, using Clojure's built-in multimethods dispatching by keys, is that message maps must not have any &quot;extra&quot; keys.  For the most part, Clojure patterns embrace the idea that you can stuff extra keys into a map without breaking contracts.  &lt;/p&gt;
</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/10449/self-like-pattern-using-multi-methods?show=10473#a10473</guid>
<pubDate>Mon, 12 Apr 2021 23:31:12 +0000</pubDate>
</item>
<item>
<title>Answered: Best way to test for an integer (including java.lang.Integer) in a multimethod dispatch?</title>
<link>https://ask.clojure.org/index.php/9978/best-test-integer-including-integer-multimethod-dispatch?show=9980#a9980</link>
<description>&lt;p&gt;You can give Long and Integer a common ancestor in a custom hierarchy that you tie to the multimethod.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;(def h (-&amp;gt; (make-hierarchy)
           (derive Long :num)
           (derive Integer :num)))
(defmulti yy type :hierarchy #'h)
(defmethod yy :num [x] (format &quot;%o is a num&quot; x))
(defmethod yy :default [x] &quot;I don't know&quot;)
(yy 7)
(yy (Integer. 42))
&lt;/code&gt;&lt;/pre&gt;
</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9978/best-test-integer-including-integer-multimethod-dispatch?show=9980#a9980</guid>
<pubDate>Mon, 28 Dec 2020 02:08:59 +0000</pubDate>
</item>
<item>
<title>Answered: Multimethods resolutions when they have the same dispatch value</title>
<link>https://ask.clojure.org/index.php/9910/multimethods-resolutions-when-they-have-same-dispatch-value?show=9911#a9911</link>
<description>&lt;p&gt;Each &quot;defmulti&quot; knows at-most-one method with any particular dispatch value.  If a second &quot;defmethod&quot; comes along, it replaces the first.  This is a cornerstone of REPL-based development.  &lt;/p&gt;
&lt;p&gt;On the other hand, there is some interesting work behind-the-scenes to dispatch a multimethod call in cases when the dispatch function returns a value that is related (by the relevant hierarchy) to more than one method's dispatch value.  In that case, see &lt;code&gt;prefer-method&lt;/code&gt;.&lt;/p&gt;
</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9910/multimethods-resolutions-when-they-have-same-dispatch-value?show=9911#a9911</guid>
<pubDate>Wed, 02 Dec 2020 10:53:59 +0000</pubDate>
</item>
<item>
<title>Answered: Implementing a type or record to support defmethod in CLJ</title>
<link>https://ask.clojure.org/index.php/9045/implementing-a-type-or-record-to-support-defmethod-in-clj?show=9046#a9046</link>
<description>&lt;p&gt;No, this is not a feature I would expect to see in Clojure. I don't understand why it's even useful in ClojureScript?&lt;/p&gt;
</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/9045/implementing-a-type-or-record-to-support-defmethod-in-clj?show=9046#a9046</guid>
<pubDate>Fri, 17 Jan 2020 19:50:07 +0000</pubDate>
</item>
<item>
<title>Answered: behavior of deftests after adding assert-expr methods</title>
<link>https://ask.clojure.org/index.php/8651/behavior-of-deftests-after-adding-assert-expr-methods?show=8652#a8652</link>
<description>&lt;p&gt;Since &lt;code&gt;is&lt;/code&gt; is a macro that uses the &lt;code&gt;assert-expr&lt;/code&gt; multi-method to expand the code at compile time, changing &lt;code&gt;assert-expr&lt;/code&gt; after running &lt;code&gt;deftest&lt;/code&gt; will not change the behavior of that test function since it has already been expanded and compiled.&lt;/p&gt;
&lt;p&gt;That is why you don't see the new &lt;code&gt;assert-expr&lt;/code&gt; functionality until you define new tests (or redefine existing ones).&lt;/p&gt;
</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/8651/behavior-of-deftests-after-adding-assert-expr-methods?show=8652#a8652</guid>
<pubDate>Tue, 24 Sep 2019 01:14:42 +0000</pubDate>
</item>
<item>
<title>Answered: MultiFn.prefers() ignores the multimethod's internal hierarchy</title>
<link>https://ask.clojure.org/index.php/3332/multifn-prefers-ignores-multimethods-internal-hierarchy?show=3581#a3581</link>
<description>Reference: &lt;a href=&quot;https://clojure.atlassian.net/browse/CLJ-2234&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2234&lt;/a&gt; (reported by palisades-lakes)</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/3332/multifn-prefers-ignores-multimethods-internal-hierarchy?show=3581#a3581</guid>
<pubDate>Wed, 26 Jun 2019 12:00:00 +0000</pubDate>
</item>
<item>
<title>Answered: Supporting `add-method` on multi fns to install a function instead of a function tail</title>
<link>https://ask.clojure.org/index.php/724/supporting-method-multi-install-function-instead-function?show=806#a806</link>
<description>Reference: &lt;a href=&quot;https://clojure.atlassian.net/browse/CLJ-2514&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;https://clojure.atlassian.net/browse/CLJ-2514&lt;/a&gt; (reported by admin)</description>
<category>Multimethods</category>
<guid isPermaLink="true">https://ask.clojure.org/index.php/724/supporting-method-multi-install-function-instead-function?show=806#a806</guid>
<pubDate>Wed, 26 Jun 2019 12:00:00 +0000</pubDate>
</item>
</channel>
</rss>