[Date Index]
[Thread Index]
[Author Index]
Re: Bug with Sequence
*To*: mathgroup at smc.vnet.net
*Subject*: [mg104633] Re: Bug with Sequence
*From*: Szabolcs Horvát <szhorvat at gmail.com>
*Date*: Thu, 5 Nov 2009 03:51:19 -0500 (EST)
*References*: <hcr7ac$8di$1@smc.vnet.net>
On 2009.11.04. 7:34, dh wrote:
> Hello,
>
> has anybody an explanation for the behavior of "Sequence"? I think it is
>
> an ugly bug.
>
> Consider the following that shoud succesively shorten the list t:
>
>
>
> t = {1, 2, 3}; j = 0;
>
> While[ ++j< 4, t[[1]] = Sequence[]; Print[t]]
>
>
>
> this returns: {2,3} three times.Dropping of the first element only seems
>
> to work once.
>
> If you say Information[t] you get:
>
> t={Sequence[],2,3}
>
Hi Daniel,
What seems to be happening when
t[[1]] = x
is evaluated is that first x is evaluated, then the first element of t
is changed to (the result of the evaluation of) x. But t itself does
not go through an evaluation process. Thus an assignment like t[[1]] is
only capable of changing the first element of t but nothing else.
If we force t to be evaluated in its entirety after every assignment,
then the program will work as expected:
While[ ++j < 4, t[[1]] = Sequence[]; t = t; Print[t]]
The fact that t[[1]] = x type assignments are not able to affect
anything else than the first element is not necessarily a bad thing.
Consider the following (admittedly unusual) example:
u = Unevaluated[{RandomInteger[], RandomInteger[]}]
If u[[1]] = 2 would trigger an evaluation of the entire contents of u,
the second element would change too. However, I wouldn't expect that to
happen in this particular example.
I hope this helps,
Szabolcs
Prev by Date:
**Re: Problem with CurrentValue and Alt key**
Next by Date:
**Re: Re: Re: graphic**
Previous by thread:
**Re: Bug with Sequence**
Next by thread:
**Re: Re: Bug with Sequence**
| |