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

  • Home
  • SEARCH
  • 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 4037300
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:19:51+00:00 2026-05-20T12:19:51+00:00

(Lisp beginner) I need to create a 2D array, and initialize each cell in

  • 0

(Lisp beginner)
I need to create a 2D array, and initialize each cell in the array. Each cell is initialized with a function that is based on data in a preceding cell. So the cell as 0,1 will be initialized with the result of a function that uses the data from cell 0,0, and so on.

I was wondering what is the proper clojure idiom for setting up a data structure like this.

  • 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-20T12:19:52+00:00Added an answer on May 20, 2026 at 12:19 pm

    Representation of your array actually depends on you needs of using it, not initializing it. For example, if you have dense matrix, you most probably should use vector of vectors like this:

    [[0, 1, 2, 3, 4],
     [5, 6, 7, 8, 9],
     [9, 8, 7, 6, 5],
     [4, 3, 2, 1, 0],
     [0, 1, 2, 3, 4]]
    

    or single vector with some additional info on raw length:

    {:length 5
     :data
     [0, 1, 2, 3, 4, 
     5, 6, 7, 8, 9,
     9, 8, 7, 6, 5, 
     4, 3, 2, 1, 0, 
     0, 1, 2, 3, 4]
    }
    

    and if you need sparse matrix, you can use hash-maps:

    {0 {0 0, 4 4},
     2 {2 7},
     3 {0 4, 2 2}}
    

    (since your 2D array is small and you generate next value based on previous one, I believe first option is better suited for you).

    If you are going to make a lot of matrix-specific manipulations (multiplication, decomposition, etc) you may want to use some existing libraries like Incanter.

    And as for filling, my proposal is to use transients and store interim results, i.e. (for one-dimensional vector):

    (defn make-array [initial-value f length]
      (loop [result (transient []), length-left length, interim-value initial-value]
        (if (= length-left 0)
            (persistent! result)
            (recur (conj! result (f interim-value)) (- length-left 1) (f interim-value))))
    

    Transients will avoid creating new data structure on each new element, and interim value will avoid need in reading previous element from transient structure.

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

Sidebar

Related Questions

Is there an emacs lisp function that will allow me to tell if a
I'm new to lisp and trying to write a recursive function that returns minimum
The Common Lisp HyperSpec says in the funcall entry that (funcall function arg1 arg2
In Lisp, I have to create a program that does the following (please visit
I'm a Lisp beginner. I'm trying to memoize a recursive function for calculating the
LISP or Haskell, I need to learn functional programming, but I heard that lisp
Does emacs lisp have a function that provides a unique object identifier, such as
I know that in Lisp a list must end with nil, but expression like
Here is a lisp procedure that simply adds 'a' to the absolute value of
In emacs lisp, posn-at-point is documented as: posn-at-point is a built-in function in C

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.