Matthew H
Matthew H

Reputation: 5879

Clojure methods ending in *

What do methods ending in * tend to have in common? I've seen a few, but have no idea if this is an established naming convention.

Upvotes: 4

Views: 203

Answers (2)

Ankur
Ankur

Reputation: 33657

Apart from what other answers have mentioned, This convention is used where the non-* version are macros and these macros emit code that calls the * functions. Even in clojure.core, let and fn are macros whose resulting code calls let* and fn* functions respectively. Other example would be sqlkorma, where non-* (where,delete,update etc) are macros and * ones (where*, delete* etc) are functions.

The reason for using this pattern is that in some cases it is not feasible to use the macro version of the API (apart from using eval, as you don't have the information at compile time), in such cases you can uses the * based functions.

Upvotes: 2

harpo
harpo

Reputation: 43188

In general I've seen this used to distinguish functions that do the same thing but with different signatures, especially in situations where overloads would create conflicting semantics. For example, list* could not be expressed as an overload of list because they are using variable arity in different ways.

In many cases (but not all), the * form is called by the non-* version.

Upvotes: 2

Related Questions