I have three patches to suggest for parenscript. Two seem relatively minor to me, but a third modifies random to be more like CL:RANDOM. It gives us the following:
CL-USER> (ps:ps (random 2.3)) "2.3 * Math.random();" CL-USER> (ps:ps (random 2)) "Math.floor(2 * Math.random());" ;; as in ps's original random
But I expect the following to be perhaps a bit more contentious...
CL-USER> (ps:ps (random (+ 2 2))) "var max1 = 2 + 2; var val2 = max1 * Math.random(); if (Math.floor(max1) === max1) { Math.floor(val2); } else { val2; };"
Hope I haven't tried too hard to be like CL here? I hope my patches are useful and would like them to be considered for inclusion.
Thanks,
Yong.
Hi Yong,
I've pushed your first two patches. As for random - you're right, calling floor on everything is not the right thing to do. OTOH I think it's the most used pattern. It's easy enough to write (* number (random)) when you really need a random floating point number.
Vladimir
2010/5/11 szergling senatorzergling@gmail.com:
I have three patches to suggest for parenscript. Two seem relatively minor to me, but a third modifies random to be more like CL:RANDOM. It gives us the following:
CL-USER> (ps:ps (random 2.3)) "2.3 * Math.random();" CL-USER> (ps:ps (random 2)) "Math.floor(2 * Math.random());" ;; as in ps's original random
But I expect the following to be perhaps a bit more contentious...
CL-USER> (ps:ps (random (+ 2 2))) "var max1 = 2 + 2; var val2 = max1 * Math.random(); if (Math.floor(max1) === max1) { Math.floor(val2); } else { val2; };"
Hope I haven't tried too hard to be like CL here? I hope my patches are useful and would like them to be considered for inclusion.
Thanks,
Yong.
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
On 5/20/10, Vladimir Sedach vsedach@gmail.com wrote:
Hi Yong,
I've pushed your first two patches. As for random - you're right, calling floor on everything is not the right thing to do. OTOH I think it's the most used pattern. It's easy enough to write (* number (random)) when you really need a random floating point number.
Vladimir
Thanks for committing all the other patches. Seems like your giant compiler rewrite went pretty well! I have not encountered any other issues in my generated output. :)
I'm not sure why you removed the floor initially or how it relates to arrays (that change has been reverted afterwards).
In case it wasn't clear, my original intent was to mimic CLHS on the input type to RANDOM, which could be either "a positive integer, or a positive float". The result is either an integer or float depending on the input. There was additional handling of the &optional upto (instead of the mandatory argument to CL:RANDOM) for backward compatibility and matching to the js Math.Random.
I was motivated by the original ps output not handling float arguments too well. I'm quite happy to use your suggestion of (* some-float (random)) for such situations, so perhaps there was no need for the patch I sent. On the other hand, that patch is a textbook example of a use case for define-ps-compiler-macro, if we ever get them :)
Good stuff!
Yong. PS: Is (funcall (@ ...) ...) to be preferred over ((@ ...) ...) now? There are still quite a few places with this in the current source.
I'm not sure why you removed the floor initially or how it relates to arrays (that change has been reverted afterwards).
The only number type in JS is supposed to be double-float, so I assumed array reference would handle rounding, but it doesn't.
I was motivated by the original ps output not handling float arguments too well. I'm quite happy to use your suggestion of (* some-float (random)) for such situations, so perhaps there was no need for the patch I sent. On the other hand, that patch is a textbook example of a use case for define-ps-compiler-macro, if we ever get them :)
Even then the big runtime case would remain.
Yong. PS: Is (funcall (@ ...) ...) to be preferred over ((@ ...) ...) now? There are still quite a few places with this in the current source.
Yes and yes. I've decided against deprecating the Scheme-style funcall though.
Vladimir
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel@common-lisp.net