Re: The Mathematica equivalent of Cons (as in Lisp)?
- To: mathgroup at smc.vnet.net
- Subject: [mg73947] Re: The Mathematica equivalent of Cons (as in Lisp)?
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Sat, 3 Mar 2007 01:16:43 -0500 (EST)
- References: <es90f4$2gc$1@smc.vnet.net>
Hi,
even when Mathematica call data {a,b,c}
a list, it is not a list in the sense of LISP.
The LISP list is in Mathematica {a,{b,{c,{}}}}
and the cons() function would be
Cons[a_,lst_List]:={a,lst}
Prepend[] will prepend an element to a Mathematica
list (that is essential an array).
In LISP cons() is a very quick operation, while
Prepend[] in Mathematica must copy the full list
to construct a new array with the prepended element.
So , cons() in LISP take always the same time
independent of the length of the list, but the
time for Prepend[] in Mathematica grow linear
with the length of the list.
Regards
Jens
wooks wrote:
> For the benefit of someone with a Scheme background.
>
> Would it be Prepend. Are there any pitfalls to be wary of?
>
>