Comparison between Python and "Ruby"

Hrvoje Niksic hniksic at srce.hr
Mon Nov 1 04:50:14 CET 1999


Dale Nagata <dnagata at creo.com> writes:

> Ian Clarke wrote:
> > * No way to automatically convert between long integer and small
> > integer.
> 
> C:\>python
> Python 1.5.1 (#0, Oct 14 1998, 20:14:21) [MSC 32 bit (Intel)] on win32
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> int(1L)
> 1
> >>> long(1)
> 1L

That doesn't look "automatically" to me.

>>> sys.maxint + 1
Traceback (innermost last):
  File "<stdin>", line 1, in ?
OverflowError: integer addition
>>> (long(sys.maxint) + 1) - 1
2147483647L

I've never seen Ruby so I don't know what it does, but in these cases
Lisp will do the right thing.  Example using CLISP:

[1]> (type-of most-positive-fixnum)
FIXNUM
[2]> (type-of (1+ most-positive-fixnum))
BIGNUM
[3]> (type-of (1- (1+ most-positive-fixnum)))
FIXNUM
[4]> (1+ 99999999999999999)
100000000000000000

In Lisp, you can use fixnums (Python ints) and bignums (Python longs)
interchangeably.  Which is a very nice feature.




More information about the Python-list mailing list