Email list hosting service & mailing list manager


fixnums on the JVM or dot-net Per Bothner 21 Sep 2016 04:22 UTC

On the JVM (and presumably .Net) platforms it seems plausible to use
unboxed int or long for fixnums - boxing them as needed.  However,
I haven't tried to work out the details or implications.  Has anyone
tried something like that?

Would 32-bit int or 64-bit long be closer to the intended
semantics of fixnums?  I suspect 32-bit int.

In Kawa there is no performance advantage of using fixnum operators,
since the standard operators compile to efficient native arithmetic
whenever the expressions are declared or inferred to have types int or long.
For example:
(let ((i ::int (f1))
       (j ::long (f2)))
   (+ i j))
This converts i to long, and then performs long addition, using the
native JVM instructions and no object allocation.

However, there is one potential advantage for Kawa to implement fixnums:
program portability among a wider group of Scheme implementations.
Though personally, I would prefer standardizing (optional) type specifiers.
Common Lisp has that, sort-of, though not with syntax (or semantics)
that I would like.

Using Kawa's type-specifier syntax:

(let ((i ::fixnum (f1))
       (j ::fixnum (f2)))
   (+ i j))

With a type-cast syntax ->fixnum:

(+ (->fixnum (f1)) (->fixnum (f2)))
--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/