Comments

There are several ways to create comments in Clojure. The most common is to use ;, which creates a comment to the end of the line. While everything after the first ; is ignored, you’ll often see multiple semicolons to make a greater visual impact:

 ;; this is a comment

Clojure also contains a comment macro that ignores its body and returns nil. This is useful to wrap around a block of existing code. However, because it’s still read by the Clojure reader, it must be valid code.

 (comment
  (​defn​ ignore-me []
 ;; not done yet
  ))

One common use of the comment macro is to save a chunk of utility or test code in a comment block at the end of the file, which is useful in combination with REPL-based development.

Clojure also contains a reader macro #_ to tell the reader to read the next form but ignore it.

 (​defn​ triple [number]
  #_(println ​"debug triple"​ number)
  (* 3 number))

In this example, the println expression is being read but ignored due to the #_ reader macro.

At this point, we’ve seen a broad overview of the basics of Clojure syntax. In the next section, we’ll dive into the constructs that Clojure provides for flow control.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.37.196