Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8916679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:18:08+00:00 2026-06-15T05:18:08+00:00

I want to display random (doc) page for some namespace. The random function name

  • 0

I want to display random (doc) page for some namespace.

The random function name I can get by:

user=> (rand-nth (keys (ns-publics 'clojure.core)))
unchecked-char

When I try to pass this to (doc) I get this:

user=> (doc (rand-nth (keys (ns-publics 'clojure.core))))
ClassCastException clojure.lang.PersistentList cannot be cast to clojure.lang.Symbol clojure.core/ns-resolve (core.clj:3883)

I’m new to Clojure and I’m not sure how to deal with this… I tried to convert this into regexp and use (find-doc) but maybe there is a better way to do this…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:18:10+00:00Added an answer on June 15, 2026 at 5:18 am

    Explanation

    The problem here is that doc is a macro, not a function. You can verify this with the source macro in the repl.

    (source doc)
    
    ; (defmacro doc
    ;   "Prints documentation for a var or special form given its name"
    ;   {:added "1.0"}
    ;   [name]
    ;   (if-let [special-name ('{& fn catch try finally try} name)]
    ;     (#'print-doc (#'special-doc special-name))
    ;     (cond
    ;       (special-doc-map name) `(#'print-doc (#'special-doc '~name))
    ;       (resolve name) `(#'print-doc (meta (var ~name)))
    ;       (find-ns name) `(#'print-doc (namespace-doc (find-ns '~name))))))
    

    If you’re new to Clojure (and lisps), you might not have encountered macros yet. As a devastatingly brief explanation, where functions operate on evaluated code, macros operate on unevaluated code – that is, source code itself.

    This means that when you type

    (doc (rand-nth (keys (ns-publics 'clojure.core))))
    

    doc attempts to operate on the actual line of code – (rand-nth (keys (ns-publics 'clojure.core))) – rather than the evaluated result (the symbol this returns). Code being nothing more than a list in Clojure, this is why the error is telling you that a list can’t be cast to a symbol.

    Solution

    So, what you really want to do is evaluate the code, then call doc on the result. We can do this by writing another macro which first evaluates the code you give it, then passes that to doc.

    (defmacro eval-doc
     [form]
      (let [resulting-symbol (eval form)]
       `(doc ~resulting-symbol)))
    

    You can pass eval-doc arbitrary forms and it will evaluate them before passing them to doc. Now we’re good to go.

    (eval-doc (rand-nth (keys (ns-publics 'clojure.core))))
    

    Edit:

    While the above works well enough in the repl, if you’re using ahead ahead-of-time compilation, you’ll find that it produces the same result every time. This is because the resulting-symbol in the let statement is produced during the compilation phase. Compiling once ahead of time means that this value is baked into the .jar. What we really want to do is push the evaluation of doc to runtime. So, let’s rewrite eval-doc as a function.

    (defn eval-doc
      [sym]
      (eval `(doc ~sym)))
    

    Simple as that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following page with some random tips: http://www.javaexperience.com/tips I want to display the
I want a web page to display several random images on load. I've thought
I am trying to display random banner each time the user refresh the page.
i want to display a set of random questions when the user presses keypad_hash
I want to display a random link + its name from an RSS feed.
I have a page on wordpress where i want to display 10 random posts.
I have a smarty template, that I want to display a random sentence on
I want to display images in a TableView . I can display one image
I want to display 1 random record from a database based on the week.
I'm building a simple random div displayer. I want to display one random li

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.