On 20 June 2010 02:13, David Nolen <dnolen.li...@gmail.com> wrote:
> On Sat, Jun 19, 2010 at 4:10 PM, Michał Marczyk
> <michal.marc...@gmail.com> wrote:
>> (defn fact [n]
>>  (loop [n n r 1]
>>    (if (zero? n)
>>      r
>>      (recur (dec n) (* r n)))))
> Huh? That doesn't look like it's going to work at all.
> 1) 1 is primitive, we know that, accept it
> 2) we don't know the type of n, what will (* r n) be?
> 3) BOOM!

Yes, I know what's going on, after reading through this rather lengthy
thread and participating in / listening in on a number of exchanges on
#clojure. I still find the notion that this code "doesn't look like
it's going to work at all" to be fairly surprising. (Also, I'd rather
not refactor a private loop so that it becomes exposed to the outside
world (presumably to be instructed to ignore the binary overload), but
that is beside the point. The (num ...) hint is a simple enough
solution, which incidentally I'd be able to live with if things were
not to go the way I prefer.)

I wanted to address the pre-BOOM points above, though:

1) With the other approach being proposed, this would read something
like "1 is primitive in primitive contexts, but will get boxed if used
as an initialiser for an unhinted local". That's rather a significant
improvement over the stylistically matching description of the
1.2-master (& 1.1) state of affairs (which I'll omit from here while
noting that apparently acceptance was pretty low on that). I'm very
happy to see Clojure moving forward w.r.t. the way in which top
numeric performance can be achieved; that leaves plenty of room for
doubting whether it should be the outright default. So, how about we
address this point...?

2) That is in fact precisely the reason why I find it odd to presume
that we know the desired type of r based on the literal alone.

The question I wanted to pose when posting that factorial example was this:

Should basic arithmetic work with no explicit hints / casts / primed
ops / whatever -- or not necessarily?

This seems like a valid question to me. If the answer is "not
necessarily", I'll probably be able to get used to the idea; if it is
"yes", or at least "hopefully", then perhaps there's something left to
tweak / change etc. Note that if there was a way to have
primitive-by-default arithmetic, yet also have naive arithmetic code
work without hinting, this would be orthogonal to the issue of the
choice of default. (In fact, it could affect my personal preference,
or at least the degree to which I care about it.)

Sincerely,
Michał

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to