[Haskell-cafe] some ideas for Haskell', from Python
Dougal Stanton
ithika at gmail.com
Wed Jan 14 17:47:41 EST 2009
> (defun avg (&rest args)
> (/ (apply #'+ args) (length args)))
>
> Or as a macro like this:
>
> (defmacro avg (&rest args)
> `(/ (+ , at 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 ;-)
D
More information about the Haskell-Cafe
mailing list