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: [mg73895] Re: The Mathematica equivalent of Cons (as in Lisp)?
  • From: Oliver Ruebenkoenig <ruebenko at uni-freiburg.de>
  • Date: Sat, 3 Mar 2007 00:48:27 -0500 (EST)
  • References: <es90f4$2gc$1@smc.vnet.net>

Hi,

I am not a scheme/lisp expert but how about:

Cons[x_, y_] := {x, y}
Car[{x_, y_}] := x
Cdr[{x_, y_}] := y
c = Fold[Cons[#2, #1] & , 1, Range[2, 5]]
Car[c]
Cdr[c]

{5, {4, {3, {2, 1}}}}

5

{4, {3, {2, 1}}}

You might be interested in a partial translation of the wizard book into 
Mathematica. You can find this here:

http://www.imtek.uni-freiburg.de/simulation/mathematica/IMSweb/imsTOC/Lectures%20and%20Tips/Mathematica/index.html

Oliver

On Fri, 2 Mar 2007, wooks wrote:

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

Oliver Ruebenkoenig, <ruebenko AT uni-freiburg.de>


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