Implementation-indpendent string-unless-number
Closed this issue · 1 comments
Yehouda commented
gadgets:string-unless-number currently uses conditionalization, which limits where it works. I think the following code would do what is required using onlu common-lisp:
(defun string-unless-number (x)
"Return the input as a string unless it can be recognized as an integer."
(if (numberp x)
x
(if (stringp x)
(or (ignore-errors (parse-integer x)) x)
(error "STRING-UNLESS-NUMBER: argument is not a number or a string : ~s" x))))
BnMcGn commented
Thanks! Fix committed.