[parenscript-devel] jQuery chain commands?

Richard KLINDA rklinda at gmail.com
Sun May 17 11:46:11 UTC 2009


>>>>> Regarding 'Re: [parenscript-devel] jQuery chain commands?'; Vladimir Sedach adds:


  > Here's one way to do it: (defpsmacro chain (&rest method-calls)
  >       (labels ((do-chain (method-calls)
  >                  (if (cdr method-calls)
  >                      `((@ ,(do-chain (cdr method-calls)) ,(caar
  > method-calls)) ,@(cdar method-calls))
  >                      (car method-calls))))
  >         (do-chain (reverse method-calls))))

  > Then you can say:

  > (ps (chain ($ "foo") (bar x z) (baz 5)))

  > => "$('foo').bar(x, z).baz(5);

I rewrote ~200 lines of JavaScript (it's a lot for me) into ParenScript
and I absolutely love it, so much cleaner and maintainable.  Thank you
for this chain macro and the whole project, superb.

  > As an aside, be careful that none of the chained functions cause
  > reflows, and cache the intermediate results when possible. The
  > jQuery style of programming is pretty much stream processing, but
  > done in a terribly slow way (mostly because current JS
  > implementations are not very good, but also because of the way
  > jQuery is implemented). It would be interesting to do something like
  > Rich Waters' SERIES for Parenscript since (like SERIES itself) you
  > can do some really mean optimizations with macros.

I'll keep that in mind, thanks.

-- 
Udv, Richard




More information about the parenscript-devel mailing list