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

natural

Conformance: SketchyLISP Core

Purpose: Convert an integer or natural number to a natural number. Integers must be positive in order to convert them.

Arguments:
A - number

Implementation:

(define (natural x)
  (letrec
    ((_natural (lambda (list-x)
      (cond ((eq? (car list-x) '+) (cdr list-x))
        ((eq? (car list-x) '-)
          (bottom (list 'natural x)))
        (#t list-x)))))
    (list->integer (_natural (integer->list x)) #t)))

Example:

(natural +123) 
=> 123

See also:
digits, integer, natural?.