What is the reverse method in Clojure?

Strings in Clojure

Strings in Clojure are a sequence of characters enclosed in double quotation marks ("").

What is the string reverse method?

The reverse string method in Clojure reverses the arrangement of characters in the string.

Syntax

:(reverse str)
Reverse syntax

Parameter

The reverse string method accepts one parameter:

  • str: This represents the string in the syntax above.

Return value

This method returns a string with all characters rearranged. Let's see an example.

Example

(ns clojure.examples.hello
(:gen-class))
(defn example []
(println (reverse "John")))
(example)

Code explanation

Line 3: We define a function example.

Line 4: We reverse the string John to nhoJ using the string reverse method like this: reverse "John".

Line 5: We called our function.

Free Resources