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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:45:31+00:00 2026-06-09T10:45:31+00:00

I’m very new to Clojure, and am trying to learn it by porting one

  • 0

I’m very new to Clojure, and am trying to learn it by porting one of my code, however I’m currently stuck in the following problem:

=> lineup
{:c b4|b4|b3|b3, :sg b6|b11|b6|b6, :sf b7|b5|b5|b5, :pf b3|b1|b1|b1, :pg b10|b10|b11|b10}
=> (validate-lineup lineup)
ArityException Wrong number of args (0) passed to: PersistentHashMap  clojure.lang.AFn.throwArity (AFn.java:437)

And here’s the function:

(defn validate-lineup [lineup]
    (map (fn [position]
        ((hash-map (position 0)
            (map
                (fn [s] (.substring s 1))
                (str/split (position 1) #"\|"))
                ))
        ) lineup))

And I’m trying to produce something like the following result:

{:c {"4" "4" "3" "3"} :sg {"6" "11" "6" "6"} :sf {"7" "5" "5" "5"} ... }

Thanks for the help, and if I’m not writing in the correct “Lisp” way, please teach me how as well.

  • 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-09T10:45:33+00:00Added an answer on June 9, 2026 at 10:45 am

    Your main problem is here:

    (fn [position]
      ((hash-map (position 0)
                 (map
                   (fn [s] (.substring s 1))
                   (str/split (position 1) #"\|")))))
    

    You create hash-map and then call it as function (note double parenthesis before hash-map). You can remove it and get this:

    (fn [position]
      (hash-map (position 0)
                 (map
                   (fn [s] (.substring s 1))
                   (str/split (position 1) #"\|"))))
    

    This way validate-lineup will return

    ({:c ("4" "4" "3" "3")} 
     {:sg ("6" "11" "6" "6")} 
     {:sf ("7" "5" "5" "5")} 
     {:pf ("3" "1" "1"` "1")} 
     {:pg ("10" "10" "11" "10")})
    

    But you need single map, not a sequence of maps. You can merge them:

    (apply merge (validate-lineup lineup))
    

    Some advices:

    Use subs instead of .substring: (fn [s] (subs s 1))
    Use destructuring when you iterate through map

    (fn [[key value]]
      (hash-map key
                 (map
                   (fn [s] (subs s 1))
                   (str/split value #"\|"))))
    

    There is a neat way to create map from vector of pairs using into function. So you can transform lineup to vector of pairs where first item of pair is a key and second is a list of numbers:

    (defn validate-lineup [lineup]
      (into {} (map (fn [[key value]]
                        [key
                         (map #(subs s 1) (str/split value #"\|"))])
                 lineup)))
    

    You can parse b4|b4|b3|b3 to sequence of numbers by re-seq:

    user=> (re-seq #"\d+" "b1|b2|b3")
    ("1" "2" "3")
    

    And finally you can replace outer map with for macro:

    (defn validate-lineup [lineup]
      (into {} (for [[key value] lineup]
                    [key (re-seq #"\d+" value)])))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.