adds docstring support to defonce


Pass all args from defonce on to def so it supports docstrings (or potentially other future features) just like def.

Docstrings and other Var metadata will be lost when the defonce is reƫvaluated.

Patch: clj-1148-defonce-6.patch

Screened by:




Alex Miller
February 20, 2014, 4:41 PM

pull out of 1.6

Linus Ericsson
August 28, 2014, 6:30 PM

This version looks for previously defined var with resolve. A repeated defonce won't affect the namespace at all if the variable is already defined and bounded.

Please confirm using (resolve '~name) is not a problem w.r.t ns-bindings or similar.

This patch also contains the tests from clj-1148-defonce-3.patch as well as the :arglists property.

(patch 4 missed one def-row, sorry for mailbox noise).

Linus Ericsson
September 9, 2014, 10:27 AM

Yet another, simpler version of defonce. No test-cases included.

This version just makes an (or (nil? v#) (not (.hasRoot v#)) test on the resolved variable. If this is true, really define by (def ~name ~@args) else do nothing.

Andy Fingerhut
January 9, 2015, 12:04 AM

Linus, while JIRA can handle multiple attachments on the same ticket with identical names, it can be confusing to do so. Would you mind renaming or removing the ones you have added with duplicate names, e.g. delete obsolete ones, perhaps? Instructions for deleting patches are in the "Removing patches" section on this wiki page:

Sean Corfield
January 10, 2018, 1:30 AM

On noticing that we have a JIRA issue at work to add docstrings to the handful of defonce calls we have (via alter-meta!), I came upon this issue and wondered what is stopping it moving forward?

Is Linus's patch an acceptable solution overall (and is just missing tests)? Or is a different approach wanted? Is this blocked by and folks want that fixed before updating defonce?




Joseph Gallo





Code and Test

Affects versions