MathGroup Archive 1996

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

Search the Archive

Re: Position[] pattern matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg4299] Re: [mg4236] Position[] pattern matching
  • From: Allan Hayes <hay at haystack.demon.co.uk>
  • Date: Sat, 29 Jun 1996 03:56:58 -0400
  • Sender: owner-wri-mathgroup at wolfram.com

>From: Harald Berndt <haraldb at nature.berkeley.edu>
>To: mathgroup at smc.vnet.net
>Subject: [mg4236] Position[] pattern matching

Harald,

Try,

Position[
	fInfo,
	x_/;(StringTake[ x[[4]], 1 ] == "L"),
	{1},
	Heads -> False
]

Allan Hayes
hay at haystack.demon.co.uk


*********
MESSAGE

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.
Part::partd: Part specification List[[4]]
     is longer than depth of object.
Part::partd: Part specification 002[[4]]
     is longer than depth of object.
General::stop:
   Further output of Part::partd
     will be suppressed during this calculation.
Out[29]=
{{5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15},
  {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25},
  {26}, {27}, {28}, {29}, {30}, {31}, {32}, {45}, {46}, {47},
  {48}, {49}, {50}, {51}, {52}, {53}, {54}, {55}, {56}}

So, I get the right answer, but only after a bunch of error messages. 
What if I look only at level 1 of the list?

In[30]:=
Position[
	fInfo,
	x_/;(StringTake[ x[[4]], 1 ] == "L"),
	1
]
Part::partd: Part specification List[[4]]
     is longer than depth of object.
Out[30]=
{{5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15},
  {16}, {17}, {18}, {19}, {20}, {21}, {22}, {23}, {24}, {25},
   {26}, {27}, {28}, {29}, {30}, {31}, {32}, {45}, {46}, {47},
   {48}, {49}, {50}, {51}, {52}, {53}, {54}, {55}, {56}}

Again, right answer, but still one error message.

I wouldn't mind, as long as I get the right answer, but if I get an 
error message might there not be cases when I don't get the right
answer?

P.S., a pet peeve: why can I say
							Select[  
fInfo, (#[[4]] == somethingorother )& ]
but need to say
							Position[  
fInfo, 	x_/;x[[4]] == somethingorother) ]

Shouldn't these allow the same formulation of the patten-match
requirements?
--
_______________________________________________________________
Harald Berndt                          University of California
Research Specialist                  Forest Products Laboratory
Phone: 510-215-4224                            FAX:510-215-4299
_______________________________________________________________



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


  • Prev by Date: BMP images
  • Next by Date: Mma on PowerMac 8100 vs. Mma on PowerMac 9500
  • Previous by thread: Re: Position[] pattern matching
  • Next by thread: Re: Position[] pattern matching