|
SketchyLISP Reference |
Copyright (C) 2007 Nils M Holm |
| <<[n>=] | [Index] | [natural?]>> |
Conformance: SketchyLISP Core
Purpose: Convert an integer or natural number to a natural number. Only non-negative integers can be converted to natural.
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)))
(else list-x)))))
(list->integer (_natural (integer->list x)) #t)))
Example:
(natural +123) => 123
See also:
digits,
integer,
natural?.
| <<[n>=] | [Index] | [natural?]>> |