In most languages there are conventions around arguments. Such as in nested loops you might use i
at the top level, then j
, then k
.
But in Clojure I don't know what the convention is. I've seen, more often than not, the use of xs
in function arguments; so why is that? Does it mean something specific? Are there other conventions?
For the naming convention, you can refer to Clojure library coding standards
Specifically:
Follow clojure.core's example for idiomatic names like pred and coll.
in fns
f, g, h - function input
n - integer input usually a size
index - integer index
x, y - numbers
s - string input
coll - a collection
pred - a predicate closure
& more - variadic input
in macros
expr - an expression
body - a macro body
binding - a macro binding vector
I.m not sure it's a standard but very often the convention is x
for a simple variable and xs
for a variable that represents a sequence. The 's' stands for sequence or a plural, which is convenient.
For instance in destructuring you can use [x & xs]
for the first and the following.
You will find also idx
for index and idxs
for more indexes.
Haskell and F# follow the same naming standard/pattern. The xs
is the plural formed of x
.
See also: https://stackoverflow.com/a/6267767/2370606
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With