-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 Thanks for the fast response!
Am 05.03.2011 17:31, schrieb Brendan Eich: > On Mar 5, 2011, at 5:41 AM, Christian Mayer wrote: > >> 1) A printf compatible format string > > http://wiki.ecmascript.org/doku.php?id=strawman:string_format > http://wiki.ecmascript.org/doku.php?id=strawman:quasis Both handle nicely the placement of "external" values into a string at given positions. But this is only one part of an printf-format string. What I'm still missing is the feature to define the format of the inserted data. This is for me more important, as that can't be easily achieved by the current ECMAScript. Here I think of stuff like: sprintf( "%f", 1.2345 ) => "1.2345" sprintf( "%.2f", 1.2345 ) => "1.23" sprintf( "%5.2f", 1.2345 ) => " 1.23" sprintf( "%05.2f", 1.2345 ) => "01.23" sprintf( "%+05.2f", 1.2345 ) => "+1.23" sprintf( "%e", 1.2345 ) => "1.2345e0" ... The big advantage of the printf style format string is, that (nearly?) every programmers knows it and there are uncountable references, explanations, tutorials on the net. Oh, and it could be easily combined with the approaches above, I guess. >> 2) A binary type conversion including float > >> 3) A fast library for small, fixed size vectors (numerical arrays) > > http://wiki.ecmascript.org/doku.php?id=strawman:typed_arrays (part of WebGL) > http://wiki.ecmascript.org/doku.php?id=strawman:binary_data (proposed for ES > Harmony) That's going the right way :) But I miss the linear algebra library to go with it. Especially for the "binary data" approach, as it's removing an order that might be implicitly known - sorry, I don't know how to express that better, so I'll make an example: // A point or vector in projective geometry - as usually used for 3D // and advanced 2D: const Vec3D = new StructType({ x: float32, y: float32, z: float32, w: float32 }); This is valid, as everybody knows that the parts of that vector are named x, y, z and w. But that vector is for everybody identical to an array with 4 elements that maps to: a = new ArrayType(float32, 4) a[0] = Vec3D.x a[1] = Vec3D.y a[2] = Vec3D.z a[3] = Vec3D.w This array allows the use of normal linear algebra algorithms and to translate, scale, project, ... by multiplying a 4x4 matrix to that vector. But we could also define the vector as: const OtherVec3D = new StructType({ x: float32, z: float32, w: float32, y: float32 }); The OtherVec3D would also be recognized by every programmer as a valid data type for the intended usecase - but it's internal order doesn't fit to any usual convention in linear algebra and thus no mapping to an array which could efficently be used for a linear algebra lib (which hopefully uses the SIMD instructions of the CPU). My suggestion is to create a "duality" for access, i.e.: v = new Vec3D; v.x = 1.0; v[0] == v.x; // -> true => This allows access of the elements in the way that is the best in that current situation. (A programmer would use the ".x"-notation usually to extract a specific value, and the "[]"-notation in algorithms) => But this would also require that the order of the elements in the {...} of the StructType({...}) is 1:1 mapped to the array positions. (AFAIK is currently the order of elements in an Object undefined although all browsers seem to keep the initialisation order) And, to make sure that a highly optimized implementation (SIMD instructions...) is possible, the language standard should predefine the most common types (i.e. Vec2Dfloat, Vec3Dfloat and Vec4Dfloat) and supply a library to handle those (especially the scalar product, matrix vector product and the matrix matrix product) CU, Christian Mayer -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iEYEAREIAAYFAk1ykUMACgkQoWM1JLkHou2DGACeNuc4r2Sgy0XVY9/71dDCx90s zC0AniGv2NlybWXM9QMp5AEj5ZXAgiIL =VzC1 -----END PGP SIGNATURE----- _______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss