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 9120875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:43:35+00:00 2026-06-17T05:43:35+00:00

I am a newbie for clojure and a little bit confused with the use

  • 0

I am a newbie for clojure and a little bit confused with the use of contains? form to different data structures.

The result of applying contains to a vector, set or a map is just what I expect, it tests if a key (or index) is present in the collection. But when it comes to a list, such as


(def li '(1 2 3)) ; define a list
(contains? li 1) ; returns false !!??

I know it is NOT that straightforward to understand how contains? works with a list, since its document says the implementation operates in a constant or log time. So here it doesnt really make sense to test in less than log time if 1 is in a list or its index range.
But in that case why doesnt it just raise an exception like when applying assoc with a list. In the assoc case the philosophy is the same – the assoc should NOT be applied to a list since it doesnt support fast-enough random-access of its elements.

I feel it inconvenient because a lot of forms in clojure return a general collection as the results, such as (vals a-map), so to test if an element exists in the value set of a map, different methods give different results – but to me they are just the different ways of saying the SAME thing.


(def a-map {:one 1 :two 2})
(contains? (vals a-map) 1) ; returns false!!
(contains? (set (vals a-map)) 1); returns true!!

So after the long explanation, my question is – what is the rational behind this design? How should we say it natively when we want to test if an element is in a value set of a map in clojure, i.e., more importantly, how should I convince myself so that I will not make stupid bugs in practice? Thanks!

  • 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-17T05:43:37+00:00Added an answer on June 17, 2026 at 5:43 am

    The source code reveals that for clojure up to and including version 1.4 contains? always return false for lists (it falls through to line 713).

    In the latest 1.5 beta it will throw an exception.

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

Sidebar

Related Questions

newbie here! I have source data that contains both simplified and traditional Chinese in
I'm a Clojure newbie. I'm trying to understand why the second form doesn't work:
newbie for clearcase. Since clearcase's config is rather different from other concept in git,
I am a Clojure newbie. I am trying to get two copies of a
Newbie here. I am trying to store the result of my search onto a
Newbie question... I am using silverlight to POST data to my GAE application class
newbie question,I have the following code where I need to match the data in
Disclaimer again: I'm a Clojure newbie. Thanks for the help. My previous question (
Newbie to web-services, so asking few basic questions I have a some data around
Newbie- I want to do 2 things with these checkboxes: Use TAB key to

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.