Hi,
Am 20.06.2010 um 01:10 schrieb Michał Marczyk:
> (defn fact [n]
> (loop [n n r 1]
> (if (zero? n)
> r
> (recur (dec n) (* r n)))))
Maybe I'm spoiled by OCaml, but why can't things be inferred?
n - We don't know.
1 - primitive
r - primitive
zero? - We don't know because of n.
dec - We don't know because of n.
* - We don't know because of n.
So, now the programmer has to choices.
1. He annotates n as primitive and *boom* full speed.
2. He does not annotate n. Then we box things.
A flag like *warn-on-boxing* can help to identify these spots. These works for
all kind of things. Not only for contrived fact and fib exampls.
(loop [n 1]
(if (pred? n)
(recur (foo n))
n))
n - primitive
foo - We don't know.
As it stands box things. Annotate foo to return something primitive and things
go fast.
There are probably tons of problems with this, I don't understand or even know.
So ignore at will.
Sincerely
Meikel
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en