Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure Function Naming Conventions

Tags:

clojure

Context

Suppose I have protocols ICursor, IFoo, IBar then I can have a function named:

(defn IFoo->IBar [foo] ... )

Now, suppose I have a function which takes two arguments

x: ICursor
y: IFoo

and output an object of type IBar.

Now, is there any standard way to denote this in a function name? For example, none of the following work:

(defn ICursor,IFoo->IBar [x y] ...)

because "," is treated as space

(defn (ICursor, IFoo)->IBar [x y] ... )

because () is treated as function application.

(defn [ICursor, IFoo]->IBar [x y] ... )

because [] is treated as vector.

Question

Is there a standard way to encode protocol types of arguments in the function name?

Thanks!


1 Answers

I don't think there is any such recommended way and it seems like sort of type annotations. There is one such project around giving type annotations to clojure code at this link.

You can use something like : (defn ICursor->IFoo->IBar [x y] ...) which denotes that the function takes ICursor and IFoo as params and return IBar, so basically last type is return type and before that everything is parameter type but I am not sure if that can be a long term or idiomatic solution because then where is the method actual name :) which is important then type annotation.

like image 187
Ankur Avatar answered Sep 30 '26 12:09

Ankur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!