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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:15:38+00:00 2026-05-24T18:15:38+00:00

I’m trying to do something similar to Python’s func(*lst) but with Clojure, and without

  • 0

I’m trying to do something similar to Python’s func(*lst) but with Clojure, and without using the apply function. My admittedly silly use case is:

{:k1 v1 (cond exp '(:k2 v2) :else '(:k3 v3))}

So if exp was true, the dict would contain {:k1 v1 :k2 v2}, otherwise {:k1 v1 :k3 v3}. I basically want a Python-esque * applied to the return value of cond. I tried playing around with data/code modes with ‘, `, and ~, though didn’t find a solution. I can repeat the cond for the individual parameters to the underlying hash-map but that kind of defeats the point.

Why? I just think it’d be cool if Clojure can do it easily. 🙂

  • 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-05-24T18:15:39+00:00Added an answer on May 24, 2026 at 6:15 pm

    No. A single form can only be a single form: it cannot magically be two of them. If this were possible, all kinds of things would break.

    In your particular example, the easy answer is

    (apply hash-map :k1 v1 
                    (cond exp   '(:k2 v2)
                          :else '(:k3 v3))
    

    The only way to do this is apply, which turns a single function parameter into zero or more function parameters, by expanding them as a list. It cannot work at the source-code level for use in things like a hash literal.

    Edit: I don’t know much Python, but I’m pretty sure Python can’t do this either. You can splat things into function calls, but not straight into source. You can’t write

    test_expr = ((x == 2), return x)
    if *test_expr
    

    or anything like it – it just isn’t possible because the compiler has to analyze the if before it can understand what to do with test_expr. Likewise in Clojure, the compiler has to analyze the hash literal before it can understand what to do with the objects inside – it can’t know that you “want” them expanded into the map expression somehow.

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

Sidebar

Related Questions

I want to construct a data frame in an Rcpp function, but when I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.