t3x.org / sketchy / library / normalize.html
SketchyLISP
Reference
  Copyright (C) 2006
Nils M Holm

normalize

Conformance: SketchyLISP Core

Purpose: Normalize a number by removing leading zeroes and plus signs.

Arguments:
X - number

Implementation:

(define (normalize x)
  (letrec
    ; remove leading zeroes from natural number
    ((skip0 (lambda (x)
      (cond ((null? (cdr x)) x)
        ((eq? (car x) 0d)
          (skip0 (cdr x)))
        (#t x))))
    (norm (lambda (x)
      (cond ((eq? (car x) '+)
          (skip0 (cdr x)))
        ((eq? (car x) '-)
          (let ((d (skip0 (cdr x))))
            (cond ((equal? d '(0d)) d)
              (#t (cons '- d)))))
        (#t (skip0 x))))))
    (list->integer
      (norm (integer->list x)) #t)))

Example:

(normalize +000511) 
=> 511

See also:
digits, ndivide.