Subject: Re: Converting an array into a list
From: Erik Naggum <>
Date: 1998/10/07
Newsgroups: comp.lang.lisp
Message-ID: <>

* Amit Kumar <>
| I'm a newbie, first of all, so please treat the question as such.  Is
| there a trivial way of converting a matrix into a list? ie, if we have a
| matrix #2A((a b) (c d)), is there a simple way of getting the list ((a b)
| (c d)), short of scanning the entire matrix element by element and
| writing to a list?

  well, the Lisp printer already does this, so we could be clever and do

(read-from-string (write-to-string <matrix>) t t :start 3)

  3 is OK as a constant because: (1) you're not going to use it on
  one-dimensional arrays, anyway, because (coerce <vector> 'list) already
  does that, (2) you're not going to use it on matrices of more than 9
  dimensions, and (3) you know full well this is a clever hack to get past
  a roadblock on your way to a better world, not a lasting solution.

  also note that this is not efficient in _any_ way.  to get an efficient
  and lasting solution, you need to traverse the matrix and cons up your
  own lists of elements.  (tip of the day: start from the far end -- you'll
  avoid the need to reverse the lists you're building.)