Re: Single function to copy list into array & vice versa?
- From: "David R. Sky" <sky@xxxxxxxxxxxxxxxxx>
- Date: Sun, 23 Apr 2006 08:52:25 -0700
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.
- References:
- Single function to copy list into array & vice versa?
- From: David R. Sky
- Re: Single function to copy list into array & vice versa?
- From: Frank Buss
- Single function to copy list into array & vice versa?
- Prev by Date: Re: "Word-Mungler" or "Critique My Code"
- Next by Date: Re: Single function to copy list into array & vice versa?
- Previous by thread: Re: Single function to copy list into array & vice versa?
- Next by thread: Re: Single function to copy list into array & vice versa?
- Index(es):
Relevant Pages
|