MathGroup Archive 2009

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

Search the Archive

Re: Length of a held expression

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96533] Re: Length of a held expression
  • From: samuel.thomas.blake at gmail.com
  • Date: Mon, 16 Feb 2009 06:54:01 -0500 (EST)
  • References: <gn8jdj$7qa$1@smc.vnet.net>

Here's one way

In[17]:= SetAttributes[heldLength, HoldAll];
heldLength[e_] := Length[Part[Hold //@ Hold[e], 1, 1, 1]]

In[19]:= b = Sequence[1, 2];

In[20]:= heldLength[{b, 2}]

Out[20]= 2

Cheers,

Sam

Nikolaus Rath wrote:
> Hello,
>
> 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
>
>  Length[Hold[{b,3}]]
>
> gives me the length of the hold expression (which is 1).
>
>
> Anyone able to help?
>
>
> Best,
>
>    -Nikolaus
>
> --
>  =C2=BBTime flies like an arrow, fruit flies like a Banana.=C2=AB
>
>   PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6  02CF A9AD B7F8 AE4E 425C


  • Prev by Date: Re: reference to cite for ProteinData[]
  • Next by Date: Re: Length of a held expression
  • Previous by thread: Re: Length of a held expression
  • Next by thread: Re: Length of a held expression