Lesson 16. Printing and handling side effects
So far, all the code we have dealt with has been code that returned some value: the result of an arithmetic calculation, the result of a conditional expression, the result of a string concatenation, or the result of a function call, where the function itself was returning a value. This code had no impact on the outside world. We ran our code examples in the REPL so we were able to see the results. But if we were running any of the code as a program from the command line we would have seen nothing.
In functional programming, a code that has no impact on the outside world is said to be with no side effects. The distinction between side effects and return value is a key idea of functional programming. We will clarify this distinction in the context of the printing functions and hopefully it will help you to understand this distinction in general.
For a program that runs from the command line to have side effects, it is not enough to return a string. The string has to be printed to the console. In this Lesson, we will learn how to print to the console in Clojure. We will also learn how to run several print expressions as part of a single expression, using the do form.