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

  • SEARCH
  • Home
  • 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 8349191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:55:14+00:00 2026-06-09T07:55:14+00:00

How to make clojure to count ‘() as nil ? For example: How to

  • 0

How to make clojure to count '() as nil?

For example:
How to make something like

(if '() :true :false) 

;to be 

:false

;Or easier 

(my-fun/macro/namespace/... (if '() :true :false))

:false

And not just if. In every way.

(= nil '()) or (my-something (= nil '()))

true

And every code to be (= ‘() nil) save.

(something (+ 1 (if (= nil '()) 1 2)))

2

I was thinking about some kind of regural expression. Which will look on code and replace '() by nil, but there are some things like (rest '(1)) and many others which are '() and I am not sure how to handle it.

I was told that macros allow you to build your own languages. I want to try it by changing clojure. So this is much about “How clojure works and how to change it?” than “I really need it to for my work.”

Thank you for help.

  • 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-09T07:55:15+00:00Added an answer on June 9, 2026 at 7:55 am

    You say you would like to change Clojure using the macros. Presently, as far as I know, this is not something you could do with the “regular” macro system (terminology fix anyone?). What you would really need (I think) is a reader macro. Things I have seen online (here, for example) seem to say that there exists something like reader macros in Clojure 1.4–but I have no familiarity with this because I really like using clooj as my IDE, and it currently is not using Clojure 1.4. Maybe somebody else has better info on this “extensible reader” magic.

    Regardless, I don’t really like the idea of changing the language in that way, and I think there is a potentially very good alternative: namely, the Clojure function not-empty.

    This function takes any collection and either returns that collection as is, or returns nil if that collection is empty. This means that anywhere you will want () to return nil, you should wrap it not-empty. This answer is very similar to mikera’s answer above, except that you don’t have to convert your collections to sequences (which can be nice).

    Both using seq and not-empty are pretty silly in cases where you have a “hand-written” collection. After all, if you are writing it by hand (or rather, typing it manually), then you are going to know for sure whether or not it is empty. The cases in which this is useful is when you have an expression or a symbol that returns a collection, and you do not know whether the returned collection will be empty or not.

    Example:

    => (if-let [c (not-empty (take (rand-int 5) [:a :b :c :d]))]
         (println c)
         (println "Twas empty"))
    ;//80% of the time, this will print some non-empty sub-list of [:a :b :c :d]
    ;//The other 20% of the time, this will return...
    Twas empty
    => nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the easiest way to make a clojure app into an executable like
Say I want to make a Clojure macro that does the following: If x
I am trying to make connect clojure to mysql, but somehow fail. My project.clj
As I asked here , I couldn't make it run Aquamacs/slime/clojure, but I could
I'd like to wrap java's PriorityQueue class in clojure for use in another part
Note: Not a duplicate of Why does Clojure recur think it should only have
I'm learning Clojure and would like some advice on idiomatic usage. As part of
I am working on a Clojure macro to help build GridBagLayout-based JPanels. I can
I'm trying to make a function in Clojure that is local to the body
I would like to be able to call clojure functions using keyword arguments like

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.