How do you return from a function early in Clojure?

后端 未结 8 1262
不知归路
不知归路 2020-12-08 13:48

Common Lisp has return-from; is there any sort of return in Clojure for when you want to return early from a function?

8条回答
  •  一整个雨季
    2020-12-08 14:03

    There isn't any explicit return statement in clojure. You could hack something together using a catch/throw combination if you want to, but since clojure is much more functional than common lisp, the chances you actually need an early return right in the middle of some nested block is much smaller than in CL. The only 'good' reason I can see for return statements is when you're dealing with mutable objects in a way that's not idiomatic in clojure.

    I wouldn't go as far as saying that it's never useful, but I think in Clojure, if your algorithm needs a return statement, it's a major code smell.

提交回复
热议问题