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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:55:11+00:00 2026-05-30T19:55:11+00:00

How do we convert elegantly between arbitrarily nested lists and arrays? e.g. ((1 2

  • 0

How do we convert elegantly between arbitrarily nested lists and arrays?

e.g.

((1 2 3) (4 5 6))

becomes

#2A((1 2 3) (4 5 6))

and vice versa

  • 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-30T19:55:12+00:00Added an answer on May 30, 2026 at 7:55 pm

    List to 2d array:

    (defun list-to-2d-array (list)
      (make-array (list (length list)
                        (length (first list)))
                  :initial-contents list))
    

    2d array to list:

    (defun 2d-array-to-list (array)
      (loop for i below (array-dimension array 0)
            collect (loop for j below (array-dimension array 1)
                          collect (aref array i j))))
    

    The multi-dimensional form for list to 2d is easy.

    (defun list-dimensions (list depth)
      (loop repeat depth
            collect (length list)
            do (setf list (car list))))
    
    (defun list-to-array (list depth)
      (make-array (list-dimensions list depth)
                  :initial-contents list))
    

    The array to list is more complicated.

    Maybe something like this:

    (defun array-to-list (array)
      (let* ((dimensions (array-dimensions array))
             (depth      (1- (length dimensions)))
             (indices    (make-list (1+ depth) :initial-element 0)))
        (labels ((recurse (n)
                   (loop for j below (nth n dimensions)
                         do (setf (nth n indices) j)
                         collect (if (= n depth)
                                     (apply #'aref array indices)
                                   (recurse (1+ n))))))
          (recurse 0))))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please suggest some elegant way to convert arrays of arrays to collections of collections
how can i convert this nested if statement to something more readable and 'elegant'?
Given a list of lists as such, is there an elegant way to convert
Is there a standard way to convert between TVarRec and Variant values? I want
I'd like to take a HashSet<String> and elegantly convert it to a string. I
Is there a more elegant solution to convert an ' Arraylist ' into a
What is the easiest or most elegant way to convert a RFC 1123 date
Convert angle in degrees to a point How could I convert an angle (in
convert this: $300 to this : 300 can't do it with intval() or (int)
select convert(varbinary(8), 1) in MS SQL Server produces output : 0x00000001 On assigning the

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.