MathGroup Archive 2003

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

Search the Archive

Re: Simple Question -- Incrementing All Elemnts in A list by 1

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44312] Re: Simple Question -- Incrementing All Elemnts in A list by 1
  • From: "John Jowett" <John.Jowett at cern.ch>
  • Date: Wed, 5 Nov 2003 10:00:35 -0500 (EST)
  • Organization: CERN
  • References: <bo7pfk$am8$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Thiery,
That's what pure functions are for (you can look them up in the Mathematica
Book)

Map[# + 1 &, {2, 3, 4, 45, 98}]

or you could simply use a rule in this case

{2, 3, 4, 45, 98} /. n_ -> n + 1

John Jowett

"Thiery Balser" <thiery.balser at gmx.net> wrote in message
news:bo7pfk$am8$1 at smc.vnet.net...
> Hi,
>
> I'm sort of stuck.
>
> I would like to have all elements in a list incremted by a given number
> without defining a supplementary function.
>
> What I've done so far is:
>
> incFunc[n_]:=n+1;
> Map[incFunc,{2,3,4,45,98}]
>
> which is all fine. It is only that I'm looking for a solution _without_
> defining the mentioned function incFunc.
>
>
> Thanks in advance,
>
> Thiery
>
>



  • Prev by Date: Re: Fonts in pdf
  • Next by Date: Re: Simple Question -- Incrementing All Elemnts in A list by 1
  • Previous by thread: Re: Simple Question -- Incrementing All Elemnts in A list by 1
  • Next by thread: Re: Simple Question -- Incrementing All Elemnts in A list by 1