Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

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: [mg96540] Re: [mg96524] Length of a held expression
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Mon, 16 Feb 2009 06:55:18 -0500 (EST)
  • References: <200902150823.DAA08017@smc.vnet.net> <E0124336-B0FE-4636-B159-31FB6DC51932@mimuw.edu.pl>

If for some reason you do not like to use Block, here is another  
pretty simple way:

  b = Sequence[1, 2];
Length @@ ReplacePart[Hold[{b, 3}], {i_, j_} :> xx]
2

Andrzej Kozlowski


On 15 Feb 2009, at 10:44, Andrzej Kozlowski wrote:

> I don't know whether this will suit your purpose (because I do not  
> know what your purpose is) but by far the simplest way to get what  
> you appear to want is:
>
> b = Sequence[1, 2];
>
> Block[{b}, Length[{b, 3}]]
> 2
>
>
> Andrzej Kozlowski
>
>
>
> On 15 Feb 2009, at 09:23, 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: Mathematica, ARPACK and implicit matrices
  • Next by Date: Re: Surface fitting error while using Fit
  • Previous by thread: Re: Length of a held expression
  • Next by thread: Re: Length of a held expression