What's the convention for using an asterisk at the end of a function name in Clojure and other Lisp dialects?

后端 未结 4 736
轻奢々
轻奢々 2021-02-01 02:03

Note that I\'m not talking about ear muffs in symbol names, an issue that is discussed at Conventions, Style, and Usage for Clojure Constants? and How is the `*var-name*` naming

4条回答
  •  耶瑟儿~
    2021-02-01 02:44

    If I understand your question correctly, I've seen instances where foo* was used to show that the function is equivalent to another in theory, but uses different semantics. Take for instance the lamina library, which defines things like map*, filter*, take* for its core type, channels. Channels are similar enough to seqs that the names of these functions make sense, but they are not compatible enough that they should be "equal" per se.

    Another use case I've seen for foo* style is for functions which call out to a helper function with an extra parameter. The fact function, for instance, might delegate to fact* which accepts another parameter, the accumulator, if written recursively. You don't necessarily want to expose in fact that there's an extra argument, because calling (fact 5 100) isn't going to compute for you the factorial of 5--exposing that extra parameter is an error.

    I've also seen the same style for macros. The macro foo expands into a function call to foo*.

提交回复
热议问题