I had also created coerce-if for coercing args from an defop arg-req:
(def coerce-if (v type) "coerce value if not nil" (if v (coerce v type)))
(def as-if (type v) (if v (coerce v type))) (defop myserv req (let id (as-if int (arg-req "id")) (pr id))
Right now I just have int2, which is like int, but converts nil to 0. Still mulling how to generalize it. Perhaps it doesn't need to be generalized.
Anybody have a better name than int2?
-----
(def default0 (f) (fn args (if (car args) (apply f args) 0))) arc> (default0.int "123") 123 arc> (default0.int nil) 0