MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: The Mathematica equivalent of Cons (as in Lisp)?


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?
> 
> 


  • Prev by Date: Re: The Mathematica equivalent of Cons (as in Lisp)?
  • Next by Date: Re: Means
  • Previous by thread: Re: The Mathematica equivalent of Cons (as in Lisp)?
  • Next by thread: Re: The Mathematica equivalent of Cons (as in Lisp)?