Re: Simple Question -- Incrementing All Elemnts in A list by 1
- To: mathgroup at smc.vnet.net
- Subject: [mg44325] Re: Simple Question -- Incrementing All Elemnts in A list by 1
- From: Daniel Reeves <dreeves at umich.edu>
- Date: Wed, 5 Nov 2003 10:01:00 -0500 (EST)
- Organization: University of Michigan Engineering
- References: <bo7pfk$am8$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
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