MathGroup Archive 2003

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

Search the Archive

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


In this case, {2,3,4,45,98} + 1 will do what you want.

More generally, you can avoid defining a throwaway function by using a 
pure function, aka the Function function.  Eg:

Map[Function[n, n+1], {2,3,4,45,98}]

(Check out the online help for Listable and Function for more.)

--- \/   FROM Thiery Balser AT 03.11.04 08:54 (Today)   \/ ---

> 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

-- 
Daniel Reeves  --  http://ai.eecs.umich.edu/people/dreeves/      

"The only way to get rid of a temptation is to yield to it."
  -- Oscar Wilde


  • Prev by Date: Re: Out of Memory Problem (beginner)
  • Next by Date: Re: two different results for Sum[Log[n]/n...
  • 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