Re: Re: Sequence is funny !

• To: mathgroup at smc.vnet.net
• Subject: [mg8974] Re: [mg8918] Re: [mg8852] Sequence is funny !
• From: David Withoff <withoff>
• Date: Mon, 6 Oct 1997 01:59:45 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```> Gilles BARBIER wrote:
> >
> >      For some people who like to understand the internal mechanism
> >      of Mathematica, I give them this little problem a friend sent to me :
> >
> >      Why Table[i,{i,Sequence[1,3]}] gives {1,2,3,4} instead of {1,2,3} !!
> >
> >      That's not a bug, I even have an explanation,if you are interested.
> >
> >      Hope it's fun,
> >
> >      Gilles.
>
> I have no explanation, but I will throw some more information into the
> pot.
>
> Table[i,{i,Sequence[1,n]}] returns {1,2,3...,n+1}
> Table[i,{i,1,n}]           returns  {1,2,3,...n}
> Table[i,{i,Sequence[0,n]}] returns {1,2,3,...n}
> Table[i,{i,0,n}]           returns {0,1,2,3...n}
>
> Since Sequence is advertised as:
>
> "Sequence[expr1, expr2, ... ] represents a sequence of arguments to be
> spliced automatically into any function."
>
> The above behavior IS a bug in my opinion regardless of how you can
> explain it with internal structure etc.  The command does not do as

I agree with the original observation that this is not a bug.

In general, the number of elements from Table[i,{i,i1,i2}] is one
greater than i2-i1.  For Table[i,{i,Sequence[1,n]}], i1 is 1, i2 is
Sequence[1,n], Sequence[1,n]-1 evaluates to n, and you end up with
n+1 elements in the result.

The description of Sequence, like the description of most functions,
carries many implied caveats, such as that the described operations
will only happen if the expression gets evaluated.  The same could
be said of 2+2, which returns 4 only if it gets evaluated.  If it
doesn't get evaluated, then there might be some other behavior.

In this example, since Table has the HoldAll attribute, the Sequence
expression does not get evaluated, at least not right away.  This
leaves several possibilities.  One possibility, which is what happens
now, is to treat the Sequence expression just like any other
iteration limit.

Dave Withoff
Wolfram Research

```

• Prev by Date: Re: Re: Sequence is funny !
• Next by Date: TraceInternal and OptionQ
• Previous by thread: Re: Re: Sequence is funny !
• Next by thread: Re: Sequence is funny !