Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1996

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

Search the Archive

Re: Position[] pattern matching

  • To: mathgroup at
  • Subject: [mg4265] Re: Position[] pattern matching
  • From: wagner at (Dave Wagner)
  • Date: Sun, 23 Jun 1996 03:10:26 -0400
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at

In article <4q093q$fiu at>,
Harald Berndt  <haraldb at> wrote:
>I just ran into a strange pattern-matching problem:
>I'm reading some infomation from a disk file with
>fInfo = ReadList[
>		{Word, Word, Word, Word, Word, Word, Word,
>		Number, Number, Number, Number}
>Now, I want all records whose 4th word starts with an "L":
>	fInfo,
>	x_/;(StringTake[ x[[4]], 1 ] == "L")
>Part::partd: Part specification List[[4]]
>     is longer than depth of object.
> (etc)

The problem is that Mathematica is trying to evaluate x[[4]], where
x either has no value or is an expression that doesn't have at
least four parts.  You can avoid this problem using:

	Unevaluated[x /; (StringTake[ x[[4]], 1] == "L")]

The computation eventually works because x[[4]] evaluates to x[[4]],
even though it generates an error message.

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at


  • Prev by Date: Re: Quicktime movies with Mma
  • Next by Date: Re: Polynomial problems - Solid Harmonics
  • Previous by thread: Re: Position[] pattern matching
  • Next by thread: Re: Position[] pattern matching