(defjsmacro max (a b) `(*Math.max ,a ,b)) ; might be nice to be able to have more than two arguments
(defjsmacro ceil (expr) `(*Math.ceil ,expr))
(define-js-compiler-macro timeout (form timeout) (js-compile `(set-timeout (lambda() ,form) ,timeout)))
(defjsmacro make-xml-http-request () `(if (slot-value window '*X-M-L-Http-Request ) (new *X-M-L-Http-Request) (new (*Active-X-Object "Microsoft.XMLHTTP"))))
Excellent suggestions John! I've forgotten about it, but it turns out we were doing min and max ourselves in the project that I'm using ParenScript for. I've put the JS math functions and a macro called with-timeout into a new file, js-utils.lisp, and pushed everything out to the ParenScript darcs repository.
One thing I didn't include is make-xml-http-request. I think that anything that is conditional on browser versions should be kept out of ParenScript itself, both to help prevent future bit rot, and because run-time browser detection is not the only (nor the best) way to handle browser differences (for example, on my project, we're planning to include different scripts based on the value of the agent HTTP header field - obviously this will not work for everyone, but the run-time approach does not work for us, so I think this is really an issue best left to applications or libraries built on top of ParenScript).
Thanks, Vladimir
On 6/19/07, John Fremlin john@fremlin.org wrote:
(defjsmacro max (a b) `(*Math.max ,a ,b)) ; might be nice to be able to have more than two arguments
(defjsmacro ceil (expr) `(*Math.ceil ,expr))
(define-js-compiler-macro timeout (form timeout) (js-compile `(set-timeout (lambda() ,form) ,timeout)))
(defjsmacro make-xml-http-request () `(if (slot-value window '*X-M-L-Http-Request ) (new *X-M-L-Http-Request) (new (*Active-X-Object "Microsoft.XMLHTTP")))) _______________________________________________ parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
"Vladimir Sedach" vsedach@gmail.com writes:
Excellent suggestions John! I've forgotten about it, but it turns out we were doing min and max ourselves in the project that I'm using ParenScript for. I've put the JS math functions and a macro called with-timeout into a new file, js-utils.lisp, and pushed everything out to the ParenScript darcs repository.
Thanks!
One thing I didn't include is make-xml-http-request. I think that anything that is conditional on browser versions should be kept out of ParenScript itself, both to help prevent future bit rot, and because run-time browser detection is not the only (nor the best) way to handle browser differences (for example, on my project, we're planning to include different scripts based on the value of the agent HTTP header field - obviously this will not work for everyone, but the run-time approach does not work for us, so I think this is really an issue best left to applications or libraries built on top of ParenScript).
Is there somewhere central where these things could be shared then?
[...]
(define-js-compiler-macro timeout (form timeout) (js-compile `(set-timeout (lambda() ,form) ,timeout)))
(Sorry about the define-js-compiler-macro for the timeouts, I have no idea why it wasn't a normal jsmacro.)
[...]
About this
(defjsmacro with-timeout ((timeout) &body body) `(set-timeout (lambda () ,@body) ,timeout))
I wonder if with-timeout is really the best name for it? I mean something like do-after-delay would make more sense.
PS. Here's another one
(defjsmacro ignore-errors (&body body) `(try (progn ,@body) (:catch (e))))
[...]
Good point. On the one hand, do-after-delay is the logical name for it. On the other, I think the name of the Javascript function should be preserved somehow since that way there will be less cognitive dissonance, and there would be one less barrier to entry for new users. How does do-set-timeout sound?
I have to run soon, so I'll add ignore-errors sometime tomorrow.
Thanks, Vladimir
On 6/19/07, John Fremlin john@fremlin.org wrote:
About this
(defjsmacro with-timeout ((timeout) &body body) `(set-timeout (lambda () ,@body) ,timeout))
I wonder if with-timeout is really the best name for it? I mean something like do-after-delay would make more sense.
PS. Here's another one
(defjsmacro ignore-errors (&body body) `(try (progn ,@body) (:catch (e))))
[...]
"Vladimir Sedach" vsedach@gmail.com writes:
Good point. On the one hand, do-after-delay is the logical name for it. On the other, I think the name of the Javascript function should be preserved somehow since that way there will be less cognitive dissonance, and there would be one less barrier to entry for new users. How does do-set-timeout sound?
Fair compromise
[...]
parenscript-devel@common-lisp.net