www.delorie.com/gnu/docs/guile/guile_171.html   search  
Buy GNU books!

Guile Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

21.2.2 Integers

Integers are whole numbers, that is numbers with no fractional part, such as 2, 83 and -3789.

Integers in Guile can be arbitrarily big, as shown by the following example.

(define (factorial n)
  (let loop ((n n) (product 1))
    (if (= n 0)
        (loop (- n 1) (* product n)))))

(factorial 3)

(factorial 20)

(- (factorial 45))

Readers whose background is in programming languages where integers are limited by the need to fit into just 4 or 8 bytes of memory may find this surprising, or suspect that Guile's representation of integers is inefficient. In fact, Guile achieves a near optimal balance of convenience and efficiency by using the host computer's native representation of integers where possible, and a more general representation where the required number does not fit in the native form. Conversion between these two representations is automatic and completely invisible to the Scheme level programmer.

Scheme Procedure: integer? x
C Function: scm_integer_p (x)
Return #t if x is an integer number, else #f.

(integer? 487)

(integer? -3.4)

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003