Re: List element manipulation
- To: mathgroup at smc.vnet.net
- Subject: [mg25448] Re: List element manipulation
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Sun, 1 Oct 2000 02:44:30 -0400 (EDT)
- References: <8r19qf$hvt@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Martin:
MapAt[# - 1 &, {1, 2, 3}, -1]
{1, 2, 2}
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565
"Martin Rommel" <Martin_Rommel at mac.com> wrote in message
news:8r19qf$hvt at smc.vnet.net...
> 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
>
>
>