Arc Forumnew | comments | leaders | submitlogin
1 point by akkartik 5482 days ago | link | parent

More than as-if, I want a really-as, which will convert nil to a default value.

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?



2 points by aw 5482 days ago | link

Maybe a function like 'only', but which defaults to 0 instead of nil?

  (def default0 (f)
    (fn args (if (car args) (apply f args) 0)))

  arc> (default0.int "123")
  123
  arc> (default0.int nil)
  0

-----

1 point by rocketnia 5481 days ago | link

You could even name it "0nly", with a zero. ^_^ That could be a bit deceptive, though.

-----