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

The Archive Base Latest Questions

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

I have an arbitrary number of lists which I would like to process using

  • 0

I have an arbitrary number of lists which I would like to process using the for macro. I want to create a function that passes a vector as the binding since the number of lists varies.

If I hard code the binding, it works as I expect:

=> (def list1 '("pink" "green"))
=> (def list2 '("dog" "cat"))
=> (for [A list1 B list2] (str A "-" B))
("pink-dog" "pink-cat" "green-dog" "green-cat")

When I try to create a vector separately and use this as the binding I hit problems. Here I manually create the bindings vector:

=> (def testvector (vec (list 'A list1 'B list2)))

this seems fine:

=> testvector
[A ("pink" "green") B ("dog" "cat")]
=> (class testvector)
clojure.lang.PersistentVector

However,

=> (for testvector (str A "-" B))
#<CompilerException java.lang.IllegalArgumentException: for requires a vector for its binding (NO_SOURCE_FILE:36)>

I don’t understand why testvector isn’t considered a vector when used as the binding in for. Grasping at straws, I put testvector in square brackets which keeps the for macro happy (it sees a vector) but now I have a vector with one element (i.e. a vector within a vector) and this doesn’t work because the binding needs to be pairs of name and collection.

=> (for [testvector] (str A "-" B))
#<CompilerException java.lang.IllegalArgumentException: for requires an even number of forms in binding vector (NO_SOURCE_FILE:37)>

Any suggestions on how to dynamically pass a vector as a binding to for would be appreciated.

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

    The key is that for is a macro. At macro-expansion time, testvector is a symbol. It will evaluate to a vector at evaluation time, but it’s not a vector from the perspective of the for macro.

    user=> (defmacro tst [v] (vector? v))
    #'user/tst
    user=> (tst testvector)
    false
    user=> (vector? testvector)
    true
    user=> (defmacro tst2 [v] `(vector? ~v))
    #'user/tst2
    user=> (tst2 testvector)
    true
    

    If you check the source for the for macro (in core.clj), you’ll see that for uses an unquoted vector? call, just like tst in the example above.

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

Sidebar

Related Questions

I have 3 lists that contain a arbitray number of doubles. Now I want
Say I have an arbitrary number of collections, each containing objects of the same
I'm adapting an XSLT from a third party which transforms an arbitrary number of
Basically NUnit, xUnit, MbUnit, MsTest and the like have methods similar to the following:
I have a binary file which I am reading to a collection of byte
I feel like I am fighting against the current when I develop ASP.NET Webform
This is not a homework. Visually it looks like a tree, but all leafs
This much I have already cobbled together (thanks to Stack Overflowers): I have a
I'm having difficulty understanding the role constraints play in GCC inline assembly (x86). I've
I'm pretty new to MVC2 and need some help on how to do something.

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.