pos
method?The pos
method is a number test method, and it is used to test if a number is greater than zero.
(pos? number)
The pos
method accepts just one parameter. This is the number it will test to see if it is greater than zero.
The pos
method returns true if the number is greater than 0
and false if the number is less than or equal to 0
.
There are times when we want to carry out a calculation and don't want our calculation to include zeros. In such situations, we use the pos
method to test the number. Let's see an example to understand this better.
(ns clojure.examples.hello(:gen-class))(defn poss [](def x (pos? 0))(println x)(def x (pos? -1))(println x)(def x (pos? 9))(println x))(poss)
poss
.0
into the pos
method. 0
.-1
into the pos
method. -1
is less than 0
.9
into the pos
method. 9
is greater than 0
.poss
function to execute the code.