Re: Single function to copy list into array & vice versa?



Thanks Frank. The identity function is defined in the manual, but is an "unbound function" when I try to run it.

It isn't "vital" that I have an identity function, I can simply use the map
function as I described previously but with a simpler "identity" function than I wrote (defun value (x) x) . So I'd use the map function

(map 'array 'value list)

I'm using XLISP because I do a lot of programming in Nyquist, an offshoot of XLISP which works with sound - I test some of my non-sound functions first in XLISP

David



On Sun, 23 Apr 2006, Frank Buss wrote:

David R. Sky wrote:

I've figured out how to copy the value of a list into an array and
vice-versa using a 'equals' function (defined below) and the map
function.

In Common Lisp there is the identity function:

http://www.lisp.org/HyperSpec/Body/fun_identity.html

My question is, is there a single LISP function which does this
without using a second function like 'equals'? I've been looking
through my XLISP2.1e manual but haven't found it so far.

I don't know, if XLISP support Common Lisp, you may download one of the
free Common Lisp implementations, but one solution:

(defun list->array (list)
(make-array (list (length list)) :initial-contents list))

CL-USER > (list->array '(1 2 3))
#(1 2 3)

(defun array->list (list)
(loop for i across list collect i))

CL-USER > (array->list #(1 2 3))
(1 2 3)

(defun equals (x)
(* x 1.0))
EQUALS
(setf my-list (list 1 2 3 4 5))
(1 2 3 4 5)
(setf my-array (map 'array 'equals my-list))
#(1 2 3 4 5)

This doesn't work in Common Lisp.


.



Relevant Pages

  • Re: Mapping None. Why?
    ... all - and because there is no identity function in python pre-defined, ... function is to define a packing function, ... special-case an arbitrary value to *mean* the packing function in ... However I don't see that this as an area that is really important (especially since map is being replaced by list-comps most of the time). ...
    (comp.lang.python)
  • Re: Complex Weirdness
    ... the identity function is such a map. ... or even arbitrary continuous maps. ... >Unsolicited bulk E-mail subject to legal action. ...
    (sci.math)