       Re: Length of a held expression

• To: mathgroup at smc.vnet.net
• Subject: [mg96567] Re: Length of a held expression
• From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
• Date: Mon, 16 Feb 2009 07:00:16 -0500 (EST)
• Organization: The Open University, Milton Keynes, UK
• References: <gn8jdj\$7qa\$1@smc.vnet.net>

```In article <gn8jdj\$7qa\$1 at smc.vnet.net>,
Nikolaus Rath <Nikolaus at rath.org> wrote:

> How can I get the length of a list in a Hold[] expression? I.e. if
>
>  b = Sequence[1,2];
>
> then I want the length of {b,3} given as 2. But
>
>  Length[{b,3}]
>
> gives me the length after splicing in b (which is 4), while

Which is 3 actually.

>  Length[Hold[{b,3}]]
>
> gives me the length of the hold expression (which is 1).

You should use *Unevaluated* rather than *Hold*.

In:= b = Sequence[1, 2];
Length[Unevaluated[{b, 3}]]

Out= 2

In:= Length[Unevaluated[1 + 2 + 3]]

Out= 3

In:= Length[Hold[1 + 2 + 3]]

Out= 1

Regards,
--Jean-Marc

```

• Prev by Date: Re: How to stretch a image
• Next by Date: Re: (2/3)[]
• Previous by thread: Re: Length of a held expression
• Next by thread: Re: Length of a held expression