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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:53:37+00:00 2026-06-13T12:53:37+00:00

I am in the progress of learning clojure after work and I’m doing this

  • 0

I am in the progress of learning clojure after work and I’m doing this by making a small game (loving the quil library) to make me familiar with the different aspects of clojure in specific and FP in general.

So, my game world exists of 3d grid of map data strucutures (vector of a vector of a vector of a map). I want to itterate over every point in 3d space (map) and change the data when a condition is met. This was my initial solution:

(the game data structure is the game state (a map))

(defn soil-gen [game]
  (let [world-x (game :world-x)
        world-y (game :world-y)
    world-z (game :world-z)]
      (for [x (range world-x) 
          y (range world-y) 
          z (range world-z) 
          :when (> z (* world-z (rand)))]
         (assoc-in game [:world x y z :type] :soil))))

But this returns a list of the results (my game state data structure) of every iteration instead of one game data structure. I should somehow be able to pass the result of each iteration back to for. Something like loop/recur probably but I think you cant combine recur with for.

Somebody a clue?

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-13T12:53:38+00:00Added an answer on June 13, 2026 at 12:53 pm

    What you can do is use reduce with for as shown below:

    (defn soil-gen [game]
      (let [world-x (game :world-x)
            world-y (game :world-y)
        world-z (game :world-z)]
    
        (reduce (fn [g [x y z]] (assoc-in g [:world x y z :type] :soil)))
                game
                (for [x (range world-x) 
                      y (range world-y) 
                      z (range world-z) 
                     :when (> z (* world-z (rand)))]
                     [x y z]))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm adapting this progress bar:http://www.richardshepherd.com/tv/audio/ to work with my playlist code, but I can't
Im working on this project for work atm where an e-learning will be played
I've been learning how to build projects using Roo and am making good progress.
I'm learning Linq and MVC2 I'm making progress, but I'm a little stuck on
I've recently started learning programming to make my own 3D OpenGL game on the
In the name of progress (and learning) how can I rid tables from my
Making lots of progress in a rails 3.1 to 3.2.6 upgrade for a Heroku
I have made some progress with the DataList and UserControl this morning but I
I've only started learning Java about 3 months ago and this is my first
I need some help on android.., apparently, I'm trying to make a progress dialog

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.