(xdef 'coerce (lambda (x type . args) (cond ((ar-tagged? x) (err "Can't coerce annotated object")) ((eqv? type (ar-type x)) x) ((char? x) (case type ((int) (char->ascii x)) ((string) (string x)) ((sym) (string->symbol (string x))) (else (err "Can't coerce" x type)))) ((integer? x) (case type ((char) (ascii->char x)) ((string) (apply number->string x args)) (else (err "Can't coerce" x type)))) ((number? x) (case type ((int) (round x)) ((char) (ascii->char (round x))) ((string) (apply number->string x args)) (else (err "Can't coerce" x type)))) ((string? x) (case type ((sym) (string->symbol x)) ((cons) (ac-niltree (string->list x))) ((int) (or (apply string->number x args) (err "Can't coerce" x type))) (else (err "Can't coerce" x type)))) ((pair? x) (case type ((string) (list->string (ar-nil-terminate x))) (else (err "Can't coerce" x type)))) ((eqv? x 'nil) (case type ((string) "") (else (err "Can't coerce" x type)))) ((symbol? x) (case type ((string) (symbol->string x)) (else (err "Can't coerce" x type)))) (#t x))))
From ac.scm
©