defmulti doc string doesn't mention needing to be passed a var for the value of :hierarchy

Description

The :hierarchy option for defmulti should be passed a var, but this is not mentioned in the doc string.

The error message from passing the hierarchy directly is rather cryptic:

Evaluation aborted on java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot be cast to clojure.lang.IRef (SOURCE_FORM_44:19).

After:

user=> (doc defmulti) ------------------------- clojure.core/defmulti ([name docstring? attr-map? dispatch-fn & options]) Macro Creates a new multimethod with the associated dispatch function. The docstring and attribute-map are optional. Options are key-value pairs and may be one of: :default The default dispatch value, defaults to :default :hierarchy The value used for hierarchical dispatch (e.g. ::square is-a ::shape) Hierarchies are type-like relationships that do not depend upon type inheritance. By default Clojure's multimethods dispatch off of a global hierarchy map. However, a hierarchy relationship can be created with the derive function used to augment the root ancestor created with make-hierarchy. Multimethods expect the value of the hierarchy option to be supplied as a reference type e.g. a var (i.e. via the Var-quote dispatch macro #' or the var special form).

Patch: 0001-CLJ-835-ReRefine-doc-string-for-defmulti-removing-examples-and-solidifying-language.patch

Screened by: Alex Miller

Environment

1.2, 1.3 beta3

Attachments

3
  • 15 Oct 2013, 03:00 PM
  • 10 May 2012, 11:16 PM
  • 14 Sep 2011, 09:11 PM

Activity

Show:

Fogus October 15, 2013 at 3:00 PM

Refined language around defmulti hierarchies and removed examples per RH's request.

Alex Miller September 28, 2013 at 3:12 PM

I don't think this patch has been updated since Rich's last comment, so moving to Incomplete (not ready to screen).

Rich Hickey December 19, 2012 at 1:58 PM

Please leave examples out of docs strings. Use precise language.

Fogus August 16, 2012 at 8:49 PM

This is a million times better than what was there before, but (who knew!?) it could be better. A couple points of contention:

  • The order under the :hierarchy section seems off. I would start with an overview of what a hierarchy is including a definition of the global hierarchy map (it's mentioned, but glossed over). I'd then move on to an example impl. Finally, I'd then add the discussion starting "Multimethods expect..." immediately followed by an example.

  • In the isa? example it would be great to show the return value.

  • You mention that the hierarchy should be supplied as a reference, which is correct, however you talk about #'. The link between e.g. var and #' could be a bit more explicit. Maybe the sentence about #' could be parenthetical?

  • It's ok to finish with a very small example of its use in defmethod, in fact a simple example specifying methods for ::shape and ::circle would clarify the intent nicely.

Scott Lowe May 10, 2012 at 11:16 PM

New patch: '0001-CLJ-835-Refine-doc-string-for-defmulti-hierarchy-opt.patch' 10/May/12.

I've attached a new doc string patch in response to Andy Fingerhut's request posted here: https://groups.google.com/forum/?fromgroups#!topic/clojure-dev/i7H82fJYL-U

Andy's request stated "Attached patch seems to have spelling mistakes, and perhaps could be worded more clearly."

I hope my new patch is an improvement upon what was there.

This patch supersedes '0001-Clarify-docstring-for-defmulti.patch' from 14/Sep/11.

Completed

Details

Assignee

Reporter

Labels

Approval

Ok

Patch

Code

Priority

Affects versions

Fix versions

Created September 2, 2011 at 9:09 PM
Updated October 25, 2013 at 10:03 PM
Resolved October 25, 2013 at 10:03 PM