MathGroup Archive 2007

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg73903] Re: [mg73849] The Mathematica equivalent of Cons (as in Lisp)?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 3 Mar 2007 00:52:51 -0500 (EST)

On 2 Mar 2007, at 12:25, wooks wrote:

> For the benefit of someone with a Scheme background.
>
> Would it be Prepend. Are there any pitfalls to be wary of?
>
>

Mathematica is quite different from Lisp and in particular  
Mathematica's Lists are quite different from Lisp lists,  which are  
rather like Mathematica's "linked lists" of the form {a,{b,....}}.  
Tghus there is really nothing in Mathematica that corresponds to cons.
You can try to immitate Lisp programming style in Mathematica but  
your programs will be very inefficient. You cna of course write your  
own implementation of Lisp in Mathematica. One obvious way is to use  
cons as the Head of a lispList and define  car, cdr etc, as follows:

lispList[a_, b___] := cons[a, lispList[b]]
car[cons[a_, b_]] := a
cdr[cons[a_, b_]] := b

etc.

However, it is much simpler and far more  efficient to simply learn  
Mathematica's one programming language.

Andrzej Kozlowski




  • Prev by Date: Re: fastest way to add up a billion numbers
  • Next by Date: Re: The Mathematica equivalent of Cons (as in Lisp)?
  • Previous by thread: Re: The Mathematica equivalent of Cons (as in Lisp)?
  • Next by thread: Re: The Mathematica equivalent of Cons (as in Lisp)?