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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:01:26+00:00 2026-06-01T23:01:26+00:00

I do not think the key-pres? function below is working the way I expect

  • 0

I do not think the key-pres? function below is working the way I expect it to. First, here is the input data.

Data from which cmp-val derived:
[“2” “000-00-0000” “TOAST” “FRENCH” “” “M” “26-Aug-99” “” “ALL CARE PLAN” “MEDICAL”]
Data that is missing the key (ssn).
[“000-00-0000” “TOAST ” “FRENCH ” “RE-PART B – INSURED “]

The problem is, if I make one of the input’s 000-00-0000 something else, I should
see that conj’d onto a log vector. I don’t, and I don’t see it printed with the if-not empty?.

(defn is-a-in-b
    "This is a helper function that takes a value, a column index, and a 
     returned clojure-csv row (vector), and checks to see if that value
     is present. Returns value or nil if not present."

    [cmp-val col-idx csv-row]

    (let [csv-row-val (nth csv-row col-idx nil)]
        (if (= cmp-val csv-row-val)
            cmp-val
            nil)))

(defn key-pres?
    "Accepts a value, like an index, and output from clojure-csv, and looks
     to see if the value is in the sequence at the index. Given clojure-csv
     returns a vector of vectors, will loop around until and if the value
     is found."

    [cmp-val cmp-idx csv-data]

    (let [ret-rc 
        (for [csv-row csv-data
                :let [rc (is-a-in-b cmp-val cmp-idx csv-row)]
                :when (true? (is-a-in-b cmp-val cmp-idx csv-row))]
            rc)]
        (vec ret-rc)))

(defn test-key-inclusion
    "Accepts csv-data file and an index, a second csv-data param and an index,
     and searches the second csv-data instances' rows (at index) to see if
     the first file's data is located in the second csv-data instance."

    [csv-data1 pkey-idx1 csv-data2 pkey-idx2]

    (reduce
        (fn [out-log csv-row1]
            (let [cmp-val (nth csv-row1 pkey-idx1 nil)]
                (doseq [csv-row2 csv-data2]
                  (let [temp-rc (key-pres? cmp-val pkey-idx2 csv-row2)]
                      (if-not (empty? temp-rc) 
                          (println cmp-val, " ", (nth csv-row2 pkey-idx2 nil), " ", temp-rc))
                      (if (nil? temp-rc)
                        (conj out-log cmp-val))))))
         []
         csv-data1))

What I want the function to do is traverse data returned by clojure-csv (a vector of vectors). If cmp-val can be found at the cmp-idx location in csv-row, I’d like that
assigned to rc, and the loop to terminate.

How can I fix the for loop, and if not, what looping mechanism can I use to accomplish this?

Thank you.

  • 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-01T23:01:27+00:00Added an answer on June 1, 2026 at 11:01 pm
    • you don’t need true?, it specifically checks for the boolean true value;
    • don’t repeat the call to is-a-in-b;
    • it would be more idiomatic (and readable) to use a-in-b? as the fn name;
    • I suggest simplifying the code, you don’t really need that let.

    Code:

    (vec (for [csv-row csv-data
               :let [rc (a-in-b? cmp-val cmp-idx csv-row)]
               :when rc)]
            rc))
    

    But, this are just some general comments on code style… what you’re implementing here is just a simple filter:

    (vec (filter #(a-in-b? cmp-val cmp-idx %) csv-data))
    

    Furthermore, this will return not only the first, but all matches. If I read your question right, you just need to find the first match? Then use some:

    (some #(a-in-b? cmp-val cmp-idx %) csv-data)
    

    UPDATE

    Rereading your question I get the feeling that you consider for to be a loop construct. It’s not — it’s a list comprehension, producing a lazy seq. To write a loop where you control when to iterate, you must use loop-recur. But in Clojure you’ll almost never need to write you own loops, except for performance. In all other cases you compose higher-order functions from clojure.core.

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

Sidebar

Related Questions

I'm using guidelines right now, but I do not think there is any way
I'm try to do pinch zoom sample.but itz not working.I think the issue is
I think in PostgreSQL you can use a function to generate your primary key
My fellow programmers did not think to add timestamps to every tables of our
Excuse the poor title, i can not think of the correct term. I have
I want to make something that makes much sense, but I think its not
I think it's not possible, but I want to make sure.
I think that is not easy to understand what I need reading title, so
I think even if we will not need interoperability between applications, and even we
It's not hard to find developers who think cursors are gauche but I am

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.