MathGroup Archive 2009

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

Search the Archive

Re: ReplacePart except first element?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg102071] Re: [mg102053] ReplacePart except first element?
  • From: Patrick Scheibe <pscheibe at trm.uni-leipzig.de>
  • Date: Wed, 29 Jul 2009 05:05:49 -0400 (EDT)
  • References: <200907280603.CAA14703@smc.vnet.net>

Hi,

on my system your function works as expected. Did you tried it on a
*new* kernel?

Cheers
Patrick

On Tue, 2009-07-28 at 02:03 -0400, mokambo wrote:
> I was trying to modify a list by adding 1 to a certain element.
> I can't understand the following result:
> 
> h[x_List, a_Integer] := ReplacePart[x, a -> x[[a]] + 1]
> 
> h[{1, 2, 3}, 2] gives {,3,3} (what happened to the first element?) but
> h[{1, 2, 3}, 1] gives {2,2,3} as expected.
> 
> Eventually I changed to:
> 
> h[x_List, a_Integer] := MapAt[Function[y, y + 1], x, a]
> 
> but the ReplacePart version still puzzles me.
> Is it because ReplacePart creates a copy instead of altering inline
> like x[[a]] = val does?
> 
> 
> 



  • Prev by Date: Mathematica syntax in W|A
  • Next by Date: Re: How to group the graph
  • Previous by thread: ReplacePart except first element?
  • Next by thread: Re: ReplacePart except first element?