Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the usual naming rule in clojure?

As i see, clojure has more characters for variable name than c/c++/java. For example:

Functions end with '?' usually return a Boolean, they are predicate.

There are also variables starting with '-', or ending with '!'.

i think these are all clojure-style naming. So, what's the usual naming rule in clojure? is there something in common for clojure programmers?

like image 456
qiuxiafei Avatar asked May 24 '12 06:05

qiuxiafei


2 Answers

It's worth looking at Clojure's Library Coding Standards which I think are still probably the best reference on Clojure coding style.

The main function naming conventions seem to be:

  • Use lowercase function names: frobnicate
  • Multiple word names use hyphens as separators: frobnicate-with-extra-fizz
  • Use namespaces to allow you to re-use good names if needed: my.special.collection/concat
  • Use ? to indicate a predicate that returns true or false: sequential?
  • Use ! to indicate a function with side effects that is not transaction safe, e.g.: set!

For local variables the following are common:

  • f, g, h - functions
  • n - integer representing a size or count
  • index, i - integer index
  • x, y - numbers
  • s - string input
  • coll - a collection
  • pred - a predicate closure
  • & more - variadic input
like image 80
mikera Avatar answered Oct 08 '22 01:10

mikera


Clojure is a dialect of Lisp, so Lisp convention may apply: http://www.cliki.net/naming%20conventions

like image 22
PeterMmm Avatar answered Oct 08 '22 01:10

PeterMmm