15 Jan 00:10
Re: some ideas for Haskell', from Python
Alex Queiroz <asandroq <at> gmail.com>
2009-01-14 23:10:42 GMT
2009-01-14 23:10:42 GMT
Hallo, On Wed, Jan 14, 2009 at 8:47 PM, Dougal Stanton <ithika <at> gmail.com> wrote: >> (defun avg (&rest args) >> (/ (apply #'+ args) (length args))) >> >> Or as a macro like this: >> >> (defmacro avg (&rest args) >> `(/ (+ ,@args) ,(length args))) >> >> The reason the macro is better is that the length of the list is known at >> compile time, so you don't need to traverse the list to calculate the length >> of the list. >> > > > I'm trying to work out how awesome the (+) operator is that you can > add the values together without needing to traverse the list> Don't need to traverse the list at run time, not compile (actually macro-expansion) time. Cheers, -- -- -alex http://www.ventonegro.org/
>
Don't need to traverse the list at run time, not compile
(actually macro-expansion) time.
Cheers,
RSS Feed