Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2000

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

Search the Archive

Re: List element manipulation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25457] Re: [mg25408] List element manipulation
  • From: Matt.Johnson at autolivasp.com
  • Date: Sun, 1 Oct 2000 02:44:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Martin-

I think the problem you are running into is that Decrement or Increment
need a variable to change and store, not just a number.  Here's an easy way
to decrease the last number by 1, however:

In[17]:=
lst = Range[116, 164, 8]
Out[17]=
{116, 124, 132, 140, 148, 156, 164}
In[20]:=
lst1 = lst /. {h___, t_} -> {h, t - 1}
Out[20]=
{116, 124, 132, 140, 148, 156, 163}
In[21]:=
lst2 = lst1 /. {h___, t_} -> {h, t - 1}
Out[21]=
{116, 124, 132, 140, 148, 156, 162}

-matt





"Martin Rommel" <Martin_Rommel at mac.com> on 09/28/2000 11:06:58 PM

cc:

Subject: [mg25457]  [mg25408] List element manipulation


I want to decrement the last number in list. This ought to be easy, but my
initial attempts did not bear fruits:

In[40]:=
MapAt[Decrement, Range[116, 166, 8], -1]

    Decrement::"rvalue": "164 is not a variable with a value, so its value
cannot be changed."

Out[40]=
{116, 124, 132, 140, 148, 156, 164--}

Do I need to use ReplacePart? That works but still gives me an error!

In[53]:=
Range[116, 166, 8] // ReplacePart[#, --Last[#], -1] &

    Set::"write": "Tag Last in Last[{116, 124, 132, 140, 148, 156, 164}] is
Protected."

Out[53]=
{116, 124, 132, 140, 148, 156, 163}

Different error here:

In[51]:=
Range[116, 166, 8] // ReplacePart[#, --#[[-1]], -1] &

    Set::"setps": "{116, 124, 132, 140, 148, 156, 164} in assignment of
part
is not a symbol."

Out[51]=
{116, 124, 132, 140, 148, 156, 163}


Anybody out there able to enlighten me?

Thanks, Martin









  • Prev by Date: Re: List element manipulation
  • Next by Date: Re: Why is Mathematica so slow ?
  • Previous by thread: Re: List element manipulation
  • Next by thread: Re: List element manipulation