Welcome! Please see the About page for a little more info on how this works.

0 votes
ago in Docs by
edited ago by

When (doc clojure-version) is called, it returns the following documentation:

clojure.core/clojure-version
([])
  Returns clojure version as a printable string.

However, unlike what one would expect from a "printable string", it actually returns an object instead when used in a context that expects a string, resulting in output such as the following:

user=> (println clojure-version)
#object[clojure.core$clojure_version 0x4f966719 clojure.core$clojure_version@4f966719]

... and if you run the object through type, as in (type clojure-version), then you get clojure.core$clojure_version and not a String.

Thus, *clojure-version* (which in contrast returns a hash map) ironically ends up being far better as a human-readable printable string representation than the "printable string" clojure-version does.

Thus, I recommend either: (1) changing the documentation to reflect reality and/or how to actually get access to the underlying string, (2) changing the behavior of clojure-version to match expectations, (3) creating a new Clojure version variable or function or macro that actually is a printable string (unlike clojure-version), or (4) overloading string and/or printing methods to process the clojure-version object type correctly.


PS: Also, one of the two web pages that direct users to report issues here (the contribution page, but not (as I later found out) the community ask page) likewise initially appeared misleading. It says to tag issue reports like this as problems, but there is no such problem tag available in the category dropdown nor its sub dropdown at the top of the "Ask a Question" form page on this Q&A site.

That info therefore initially appeared out of date or seemingly unmaintained. I thus recommend that the page directing people here be amended to disambiguate that (such as by mentioning both the category and tag systems to alert users of the distinction in advance) so that people reporting issues are not as likely to give up when they seemingly can't find the supposed tags they are supposed to apply in the category system, which initially will likely seem to most new users to be the "tags" being referred to.

You have probably already lost some potential reports that way from less motivated/persistent users over time without realizing it, I would guess. Only after writing this did I realize that there is a second tag-like system was present at the bottom of this page and had to rewrite the above PS note text to match that more nuanced but still misleading-to-newcomers reality.

Both pages directing users here (not just the "ask" page) should mention the existence of both categories and tags to prevent confusion, I think.


Anyway though, thank you for your time and reading and for providing this wonderfully expressive and capable programming language!

1 Answer

+1 vote
ago by

clojure.core/clojure-version is a function.

If you call it by wrapping it in parentheses, it should hopefully do what you want:

user> (println (clojure-version))
1.11.1

In clojure, functions are first class and can be passed around. If you don't include the parentheses, it will actually try to print the function rather than the result you would get by calling the function! It might seem like trying to refer to a function rather than calling it should be an error, but it turns out to be a very useful tool in functional programming.

ago by
Ah ok, good to know. I am not yet fully accustomed to reading `(doc ...)`'s notation and didn't see any clear indicators (e.g. a text label/header saying `function` for example) that it wasn't an immutable global variable.

I just assumed it would be an immutable compile-time global, since that is how I'd do it.

I have used other Lisp/Scheme (s-expression) languages before though and I am aware that functions are first class values and of various other highly expressive features of such languages.

It is good that you noted that anyway though, in case someone else doesn't know that and arrives at this page.

Anyway, thank you for your time and efforts and have a wonderful day!
...