Functions are generally code blocks that carry out certain instructions in an application. These block of code can be called more than once during the runtime or execution time of the application.
In Clojure an anonymous function is a function without a name and as such, it can not be referenced. Let's see how it works below.
(fn [message] (println message) )
Let's see an example to understand this clearly.
(ns clojure.examples.hello (:gen-class)) ( (fn [message] (println message)) "John Doe is popular" )
We create an anonymous function that prints a string.
Line 3: Observe the
fn syntax used and the argument passed to the function
[message]. Since the function is an anonymous function, we only create it anonymous function where it'll be used.
View all Courses