Sorry,  correct URL is:

http://www.cs.toronto.edu/~gfb/scheme/simple-macros.html


From my Android phone on T-Mobile. The first nationwide 4G network.

-------- Original message --------
From: Matt Welland <[email protected]> 
Date: 10/05/2013  1:10 PM  (GMT-07:00) 
To: Loïc Faure-Lacroix <[email protected]>,chicken-users 
<[email protected]> 
Subject: Re: [Chicken-users] Macro expansion help 
 
I found that the "simple macros in scheme" approach found at 
http:/www.cs.toronto.edu/~gfb/simple-macros.html is adequate for most macros I 
need to write and far easier than fully fledged macros.  Maybe it will help you 
get going. 


From my Android phone on T-Mobile. The first nationwide 4G network.



-------- Original message --------
From: Loïc Faure-Lacroix <[email protected]> 
Date: 10/05/2013 11:24 AM (GMT-07:00) 
To: [email protected] 
Subject: [Chicken-users] Macro expansion help 


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

Reply via email to