Search code examples
clojure

How do you make an array of lists in clojure?


So I'm working on a compiler lexer, and I am defining the transition table with (make-array rows) where rows is a list of list of lists.

However, I'm running into memory issues creating a tall nested list of 800 * 127 * '() rows, and then converting it back to array.

Is there a way to create an empty 2d-array, and then dynamically set its cells with lists? List sizes of each cells would not be same.


Solution

  • If you don't actually need to initialize each value to clojure.lang.PersistentList$EmptyList (aka '()), this can be as simple as:

    (make-array clojure.lang.PersistentList 800 127)
    

    ...that said, I don't particularly recommend it. Is there a reason you can't use a vector of vectors?