পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Friday, January 27, 2017

Clojure - Numbers

Numbers datatype in Clojure is derived from Java classes.
Clojure supports integer and floating point numbers.
  • An integer is a value that does not include a fraction.
  • A floating-point number is a decimal value that includes a decimal fraction.
Following is an example of numbers in Clojure.
(def x 5)
(def y 5.25)
Where ‘x’ is of the type Integer and ‘y’ is the float.
In Java, the following classes are attached to the numbers defined in Clojure.
Numbers To actually see that the numbers in Clojure are derived from Java classes, use the following program to see the type of numbers assigned when using the ‘def’ command.

Example

(ns clojure.examples.hello
   (:gen-class))

;; This program displays Hello World
(defn Example []
   (def x 5)
   (def y 5.25)
   (println (type x))
   (println (type y)))
(Example)
The ‘type’ command is used to output the class associated with the value assigned to a variable.

Output

The above code will produce the following output.
Java.lang.long
Java.lang.double

Number Tests

The following test functions are available for numbers.
S.No. Numbers & Description
1 zero? Returns true if the number is zero, else false.
2 pos? Returns true if number is greater than zero, else false.
3 neg? Returns true if number is less than zero, else false.
4 even? Returns true if the number is even, and throws an exception if the number is not an integer.
5 odd? Returns true if the number is odd, and throws an exception if the number is not an integer.
6 number? Returns true if the number is really a Number.
7 integer? Returns true if the number is an integer.
8 float? Returns true if the number is a float.

No comments:

Post a Comment