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: [mg73932] Re: The Mathematica equivalent of Cons (as in Lisp)?
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 3 Mar 2007 01:08:37 -0500 (EST)
  • Organization: The Open University, Milton Keynes, UK
  • References: <es90f4$2gc$1@smc.vnet.net>

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

My Scheme is a little bit rusty, but I hope that the following comments 
will help you.

Prepend must be the closest equivalent expression to cons. Note that the 
order of augments is the inverse of a cons. (Also, I am not sure what 
might be the Mathematica equivalent of a List/Scheme dotted pair.)

Mathematica built-in functions First and Rest are the equivalent of car 
and cdr, respectively. (Also, you might be interested in Most and Last.)


In Scheme:
==========

(cons '1 '(2 3 4))
--> (1 2 3 4)

(cons '(1 3 3) '(4 4 5))
--> ((1 3 3) 4 4 5)

In Mathematica:
===============

In[1]:=
Prepend[{2, 3, 4}, 1]

Out[1]=
{1, 2, 3, 4}

In[2]:=
Prepend[{4, 4, 5}, {1, 2, 2}]

Out[2]=
{{1, 2, 2}, 4, 4, 5}

Regards,
Jean-Marc



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