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

abs

Conformance: R5RS Scheme

Purpose: Compute the absolute value of a number.

Arguments:
X - number

Implementation:

(define (abs x)
  (letrec
    ((_abs
       (lambda (x)
         (cond ((eq? (car x) '-) (cdr x))
           ((eq? (car x) '+) (cdr x))
           (else x)))))
    (list->integer (_abs (integer->list x)) #t)))

Example:

(abs -125) 
=> 125

See also:
digits, -, negative?.