<< Back to previous view

[CLJ-835] defmulti doc string doesn't mention needing to be passed a var for the value of :hierarchy Created: 02/Sep/11  Updated: 25/Oct/13  Resolved: 25/Oct/13

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.2
Fix Version/s: Release 1.6

Type: Defect Priority: Minor
Reporter: Hugo Duncan Assignee: Unassigned
Resolution: Completed Votes: 1
Labels: docstring
Environment:

1.2, 1.3 beta3


Attachments: Text File 0001-Clarify-docstring-for-defmulti.patch     Text File 0001-CLJ-835-Refine-doc-string-for-defmulti-hierarchy-opt.patch     Text File 0001-CLJ-835-ReRefine-doc-string-for-defmulti-removing-examples-and-solidifying-language.patch    
Patch: Code
Approval: Ok

 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



 Comments   
Comment by Meikel Brandmeyer [ 14/Sep/11 3:11 PM ]

Modified doctoring to clarify the usage of :hierarchy.

Comment by Scott Lowe [ 10/May/12 5: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.

Comment by Fogus [ 16/Aug/12 2: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.
Comment by Rich Hickey [ 19/Dec/12 7:58 AM ]

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

Comment by Alex Miller [ 28/Sep/13 9:12 AM ]

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

Comment by Fogus [ 15/Oct/13 9:00 AM ]

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

Generated at Wed Nov 26 22:31:00 CST 2014 using JIRA 4.4#649-r158309.