Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: Bug with Sequence and Assignment by Part...

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121639] Re: Bug with Sequence and Assignment by Part...
  • From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
  • Date: Fri, 23 Sep 2011 03:44:30 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j5f6ai$q8a$1@smc.vnet.net>

On Thu, 22 Sep 2011 12:31:30 +0100, BernieTheJet <berniethejet at gmail.com>  
wrote:

> If one patches a list of items into a list using Sequence[], it
> appears that Mathemaitca doesn't properly update the data structure:
>
> temp = Range[3];
> temp[[2]] = Sequence @@ {a, a, a};
> temp
>
> as expected :
>     -> {1, a, a, a, 3}
>
> FullForm[temp]
>   also looks right:
>    -> List[1,a,a,a,3]
>
> As does:
> Length[temp]
>    -> 5
>
> Ok, so far all is fine.  But subsequent additions to the same place do
> not increase the length of temp, as one might expect:
> temp[[2]] = Sequence @@ {b, b, b};
> temp
> FullForm[temp]
>
>        -> {1, b, b, b, 3}
> and  -> List[1,b,b,b,3]
>
> And, despite the Length of temp being '5', in fact there is no way to
> put anything into position '5' of temp:
>
> Length[temp]
>    -> 5
> temp[[5]] = Sequence @@ {c, c, c}
>    -> Set::partw: Part 5 of {1,Sequence[b,b,b],3} does not exist. >>
>
> Here we finally see what is going on, somewhere temp is being stored
> as {1,Sequence[b,b,b],3}, but all the functions that go to request
> info from it first perform the evaluation of Sequence hence returning
> the expected results.
>
> One can force Mathematica to sort things out with the otherwise  
> meaningless:
> temp=temp
>
> Surely I am not the first to encounter this, and surely it constitutes
> at least one bug, (and surely it is shouldn't be in Mathematica 8!).  I  
> mean,
> it seems to me that FullForm and Length should also detect the
> presence of Sequence and act differently than they do here.
>
> Bernard
>

Just to note:

OwnValues[temp] = {HoldPattern[temp] :> {1, Sequence[a, a, a], 3}}

so I am not sure that this can really be called a bug so much as  
unintuitive behaviour when looked at from a certain perspective. Seen from  
another, it would certainly be quite inconvenient if Sequence was  
flattened out without even having to evaluate the expression it appears  
within (for one thing, this would make SequenceHold unworkable).




  • Prev by Date: Re: How to distribute specific tasks to specific subkernels?
  • Next by Date: Re: Bug with Sequence and Assignment by Part...
  • Previous by thread: Re: Bug with Sequence and Assignment by Part...
  • Next by thread: Re: Bug with Sequence and Assignment by Part...