You dont need this script the functionality is built in. Ita called a particle expression node and it evaluetes MUCH MUCH faster than what you can get with your melscript and you can even animate it over time. Plus its way easier, so easy thet it preempts your entire script. More than this it also exemplifies that you dont really do thsi kind of stuff in mel. So whenevre you say words parse and algorithm yoru overstepped what mel is supposed to do, to pogress is going only to make you really agravated.
So basically if you really nee dto script this its (its a bit over convoluted yes but im just being snobbish):
{
// $t other builtin parameters exist too such as .pos0 .id etc
$yourFunc = "<>";
$crv = curve -d 1 -p 0 0 0 -p 1 0 0
-k 0 -k 1 -n InitialParticleGen;
// you can modify the rebuild curve node to make more particles
// but due toa glitch in maya caching not less.
$crvs = rebuildCurve -ch 1 -rpo 0 -d 1 -s 9 $crv;
$crvs[1] = $crv;
$shape = listRelatives -children $crvs[0];
$particle = createNode particle;
//delte history to get rid of theese if you dont want to change your expression/amount later
connectAttr ($shape[0]+".worldMatrix[0]") ($particle+".targetGeometryWorldMatrix");
connectAttr ($shape[0]+".worldSpace") ($particle+".inputGeometry");
sets -e -forceElement initialShadingGroup $particle;
dynExpression -s ("float $t = .id/(.count-1);.pos ="+
$yourFunc +";") -c $particle;
for ($item in {".vir",".vif"})
setAttr ($particle + $item) 1;
for ($i in $crvs)
setAttr ($i + ".io") 1;
}
All you really need is:
file -f -new;
emitter -speed 0;
particle;
connectDynamic -em emitter1 particle1;
dynExpression -s ".pos = <>"
-c particleShape1;
If OTOH you knew about expressions you can also just calculate worldspace in expressions too not much point tough, if for soem reason you must have the particle placed in a different localspace.