MathGroup Archive 1996

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

Search the Archive

Re: Position[] pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg4265] Re: Position[] pattern matching
  • From: wagner at motel6.cs.colorado.edu (Dave Wagner)
  • Date: Sun, 23 Jun 1996 03:10:26 -0400
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4q093q$fiu at dragonfly.wolfram.com>,
Harald Berndt  <haraldb at nature.berkeley.edu> wrote:
>I just ran into a strange pattern-matching problem:
>
>I'm reading some infomation from a disk file with
>
>fInfo = ReadList[
>		"NDEC:EWW:RODDAT.PRN",
>		{Word, Word, Word, Word, Word, Word, Word,
>		Number, Number, Number, Number}
>]
>
>Now, I want all records whose 4th word starts with an "L":
>
>In[29]:=
>Position[
>	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:

    Position[
	finfo,
	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 princon.com
		http://www.princon.com/princon

==== [MESSAGE SEPARATOR] ====


  • 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