racket icon indicating copy to clipboard operation
racket copied to clipboard

Add `get-failure-result` to racket/function

Open lexi-lambda opened this issue 2 years ago • 1 comments

This adds a very simple function named get-failure-result to racket/function. It is essentially just

(define (get-failure-result v)
  (if (procedure? v) (v) v))

except that the version in this PR also includes an explicit arity check.

Since this function is so simple, the convenience it affords is obviously extremely minor. Still, I’ve written it so many times that it feels worth putting somewhere, especially since we already have failure-result/c.

lexi-lambda avatar Dec 07 '23 17:12 lexi-lambda

the version in this PR also includes an explicit arity check

I have also written this function multiple times, but I think I have rarely if ever implemented an explicit arity check. That seems quite useful for cases when the argument isn't already protected by failure-result/c. It might be worth adding an optional #:who argument for even better error reporting in such cases.

LiberalArtist avatar Jan 21 '24 06:01 LiberalArtist