MathGroup Archive 2005

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

Search the Archive

Re: Position different in 5.0 and 5.1?

  • To: mathgroup at
  • Subject: [mg56089] Re: Position different in 5.0 and 5.1?
  • From: David Bailey <dave at>
  • Date: Fri, 15 Apr 2005 04:47:30 -0400 (EDT)
  • References: <d3lraa$s6b$>
  • Sender: owner-wri-mathgroup at

J R Gog wrote:
> I've recently upgraded from 5.1 from 5.0 and have found that some of my old 
> notebooks don't seem to work. I think I have the essence of what I'm utterly 
> confussed about in this example:
> Position[{"asd", "dsa"}, x_ /; (StringTake[x, 1] == "a")]
> What I want is the position of list entries which have first character "a". 
> In 5.0, this line works. In 5.1, I get an error that StringTake is being fed 
> a string.
> I can't find any documentation that explains what has changed to have this 
> effect. I'm sure I've missed something obvious, but if anyone can explain to 
> me what has changed, it would be very helpful indeed. I know I can do 
> everything some other way, but I need to know exactly what old stuff I need 
> to change!
> Thanks
> Julia Gog
You can understand what is happening here by running:

Position[{"asd", "dsa"}, x_ /; (Print[x]; StringTake[x, 1] == "a")]

As you can see, the code attempts to execute StringTake[List,1] and 
fails as you describe! Presumably StringTake just used to return 
unevaluated in such cases in earlier versions of Mathematica. The answer
is to force the pattern x to only match a string:

Position[{"asd", "dsa"}, x_String /; (StringTake[x, 1] == "a")]


David Bailey

  • Prev by Date: Re: SSH Remote Kernel on Windows - Can it be done?
  • Next by Date: Re: Legendre Polynomials
  • Previous by thread: Re: Position different in 5.0 and 5.1?
  • Next by thread: Re: Position different in 5.0 and 5.1?