Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use exclamation mark in clojure (or lisp)?

Tags:

naming

clojure

They say that use exclamation marks when naming impure functions.

But I don't exactly understand the "impure" functions. Are they

  • functions change state of their arguments (via reset!, alter, java-object-methods, ...)
  • functions occur side-effect (for example, print, spit, ...)
  • or both?

Obviously, official clojure apis don't have bang!s on every case above. I wonder when should I put them and need your help to make my code saner.

like image 650
Bak Yeon O Avatar asked Dec 16 '13 08:12

Bak Yeon O


People also ask

What does an exclamation mark mean in programming?

In programming and scripting languages, the exclamation mark is used as "not." For example, "! =" also means not equal. See our operator definition for further information. Used to help identify a nonexecutable statement.

Why do we use exclamation mark in Python?

In general, using an exclamation mark before the command will pass the command to the shell (not to the Python interpreter). Note that this differs from executing a python program in IDLE: IDLE restarts the Python interpreter session and thus deletes all existing objects before the execution starts.

Why do we use exclamation mark in Java?

In java,exclamation mark ( ! ) that is used for inverted the value and also we call Boolean negation operator ( != being not equal to). example:if(string variable!= null) here check whether string variable is null or not.


1 Answers

I would say you don't need to put ! on every impure function. Community Clojure Style Guide recommends:

The names of functions/macros that are not safe in STM transactions should end with an exclamation mark.

So, basically, end with ! functions that change state for atoms, metadata, vars, transients, agents and io as well.

Thanks to @noisesmith for update.

like image 82
mishadoff Avatar answered Sep 22 '22 16:09

mishadoff