I have been using Clojure for just under a week, but ...

I have been using CL for almost three years now and have lately been
looking
at and actually using Clojure. I think that it should be easy to write
correct code then put it a bit of work later to make it fast.

On Jun 18, 12:44 pm, Christophe Grand <christo...@cgrand.net> wrote:
> On Fri, Jun 18, 2010 at 8:58 AM, Richard Newman <holyg...@gmail.com> wrote:
> > It only takes one library to screw up, and the whole stack falls down.
> > Screwing up can occur because of omission (fact being written with a "1",
> > not "1N", and not being tested with large inputs), or by design.
>
> It can already happen: a library can screw you by design.
>
> (defn fact [n] (loop [r (int 1) n (int n)] (recur (* r n) (dec n))))
> user=> (fact 40)
> java.lang.ArithmeticException: integer overflow (NO_SOURCE_FILE:0)
>
> Actually people who want numerical perfs have to do very invasive type
> hinting and other interfaces workaround because primitives are...
> primitives (not objects).
>
> With contagious bigints (let's nick name them "safeints" and assume
> they are not BigInteger but something à la kawa) a single N on
> literals or having all your inputs going through a safeint conversion
> would trigger safe computations (unless you try to call a static
> primitive-hinted fn but the compiler would then bark).
>
> Of course a rogue fn can still internally convert to primitives and
> overflow but you can't do anything to protect you from that.
>
> As for mixing several numebr representations in a single collection, I
> think it's a problem of normalizing data but most of the time your are
> either in safeland or in fastland so your representations will be
> homogeneous (safehints or (boxed) primitives).
>
> A middleground may be to keep the semantics proposed by Rich but:
> * integer literals default to safeint (unless suffixed by L for long)
> * scientific notation and decimal literals default to double (unless
> suffixed by M or N)
> * implement a better bigint.
>

This, I feel, would be a win/win.

+1

> Christophe
>
> --
> European Clojure Training Session: Brussels, 23-25/6http://conj-labs.eu/
> Professional:http://cgrand.net/(fr)
> On Clojure:http://clj-me.cgrand.net/(en)

---
Martin.

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