On Jun 18, 2010, at 1:23 AM, Mark Engelberg wrote:

On Thu, Jun 17, 2010 at 9:20 PM, David Nolen <dnolen.li...@gmail.com> wrote:
The problem is that it distinctly *not* easy to write fast numeric code in
Clojure. It requires expert Clojure knowledge.

Right, but with just the prim branch and a shorthand for long literals, you get:
(defn ^:static fib ^long [^long n]
 (if (<= n 1L)
   1L
   (+ (fib (dec n)) (fib (- n 2L)))))

which really isn't that bad.  So my claim is that the prim branch gets
you far enough along the road to easy fast numeric code, without
screwing with the numeric tower.


This L suffix idea is a non-starter. Here's why:

We're in a reader based language. The reader reads objects. When the reader reads 42, it must return an object. It cannot return an int or a long primitive. Right now, it returns an Integer. I've also conducted experiments where it returned a Long. Certainly 42000000000 will be a Long. What different thing would the reader return given 42L, or 42000000000L? Given an int 42 what should the printer print? And long 42, Long 42? Would (= 42L (read-string (pr-str 42L)))?

------
The second thing I don't see being acknowledged is that the real problem here is the semantic difference. It's not a matter of getting at a primitive operation when handed a boxed number - that already happens, and pretty efficiently. It is the fact that the results have to go somewhere, and the difference in 'where' creates a difference in semantics. In master right now:

(+ x y)

and

(+ (identity x) y)

can produce different results. We already have bug reports around this, and user confusion. Fixing it requires adopting a single semantic for +. Choosing auto-promotion precludes the use of + on primitives, a huge loss IMO. Choosing throw-on-overflow precludes auto- promotion, but preserves polymorphism otherwise, and gives the compiler free reign to optimize since it will never be altering the semantics by doing so.

I don't see a way around this fundamental dichotomy. The semantics for + should be unified, and the operator that makes the other choice needs to be called something else, or placed somewhere else.

Rich

--
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