If you're considering memoization of an expensive but repeatable computation you may have an easier time of it using parameters rather than syntax.
See define-parameter: http://wiki.call-cc.org/eggref/4/miscmacros And parameterize: http://wiki.call-cc.org/man/4/Non-standard%20macros%20and%20special%20forms#parameterize And SRFI-39: http://wiki.call-cc.org/man/4/Parameters And SRFI-26: http://wiki.call-cc.org/man/4/Non-standard%20macros%20and%20special%20forms#cut Anyhow, a few go-to sources for macros: http://wiki.call-cc.org/man/4/Macros https://en.wikipedia.org/wiki/Hygienic_macro https://en.wikipedia.org/wiki/R5RS#Hygienic_macros As always, check out #chicken on irc.freenode.net for some insightful feedback. -Dan On Sat, Oct 5, 2013 at 11:24 AM, Loïc Faure-Lacroix <[email protected]> wrote: > Hi, new to scheme and I'd like to know what is the ideal thing to do for a > case like the following. I'd like to create a library that will compute > bezier curves of N order. > > I already made a something that seems to work but I believe it could be > improved using macro expansion. > > For the people who aren't aware of it, a bezier is a type of curve that > has 2 points and n control points. The function can be computed recursively > or iteratively. The recursive version is quite trivial to write but will be > quite expensive when the bezier has multiple control points. The order of > complexity of the recursive algorithm is O(n!) If I'm not mistaken. The use > of iterative algorithm would create a version of complexity O(n) Since we > have to loop over each points. > > Using macro expansion, we could expand the function to sum each points > without having to loop over a list of points. Using expansion, we can also > replace some of the values with fixed constant. > > https://gist.github.com/llacroix/6844267 > > For example, as I understand, the coefficient in the calc define could be > expanded since they we could guess them at compile time. If we create a > bezier of 4 points, we will have something like this > > (nCr 3 0) = 1 > (nCr 3 1) = 3 > (nCr 3 2) = 3 > (nCr 3 3) = 1 > > For each call to a bezier with 4 points, it is not necessary to recompute > coefficient because they will always be the same. The same things goes for > (- n i). > > But to be honest, I have no idea how to rewrite a function at compile > time. I saw how people use "define-syntax" to add some sugar to the > language, but I hardly understand how to actually transform a function > using macros. The bezier example should be simple enough to understand how > it works. > > Once I have this done, I'll write a blog post so other people can get a > "painless" introduction to function rewriting. > > Thanks in advance, > Loïc > > _______________________________________________ > Chicken-users mailing list > [email protected] > https://lists.nongnu.org/mailman/listinfo/chicken-users > >
_______________________________________________ Chicken-users mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-users
