Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Clojure Data Types

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

;; This program displays Hello World
(defn Example []
   ;; The below code declares a integer variable
   (def x 1)
   
   ;; The below code declares a float variable
   (def y 1.25)
   
   ;; The below code declares a string variable
   (def str1 "Hello")
   (println x)
   (println y)
   (println str1))
(Example)

Clojure Example2 Delimiters

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

;; This program displays Hello World
(defn Example []
   (println [+ 1 2 3]))
(Example)

Clojure Basic Syntax Delimiters

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

;; This program displays Hello World
(defn Example []
   (println (+ 1 2 3)))
(Example)

Clojure Basic Syntax General Form of a Statement

(ns clojure.examples.hello
   (:gen-class))
(defn Example []
   (println (str "Hello World"))
   (println (+ 1 2)))
(Example)

Clojure Basic Syntax Hello World

(ns clojure.examples.hello
   (:gen-class))
(defn hello-world []
   (println "Hello World"))
(hello-world)

Eu.clj

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

;; Eu1
(println
    (apply + 
        (filter 
            #(zero? 
                (min (mod % 3) (mod % 5))
            )
            (range 1000)
        )))

day-of-the-programmer

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

(defn hello-world [username]
(println (format "Hello, %s" username)))

(hello-world "world")

(defn is_leap_j[y] (= 0 (rem y 4)))
(defn is_leap_g[y] 
  (or (= 0 (rem y 400))
    (and (= 0 (rem y 4)) (not= 0 (rem y 100)))
  )
)
(defn get_m [y] 
    (let [
        normal_md [ 31  28  31  30  31  30  31  31  30  31  30  31]
		leap_md [ 31  29  31  30  31  30  31  31  30  31  30  31]
		y1918_md [ 31  15  31  30  31  30  31  31  30  31  30  31]
      ]
      (cond
      (<  y  1918) (if (true? (is_leap_j y)) leap_md normal_md)
      (> y 1918) (if (true? (is_leap_g y)) leap_md normal_md)
      :else y1918_md
      )
    )
)
(defn get_md[y]
 (let [ day_of_pgm 256
        md (get_m y)
        m_acc (map-indexed (fn [idx itm] [idx (reduce + (take (inc idx) md) ) ] ) md)
        m  (first (filter (fn [n] (> (last n) day_of_pgm)) m_acc ) )
     ]
     [(first m)  (- (nth md (dec (first m))) (- (last m) day_of_pgm ) 1) ]
   )
)
(
	let [
		year 2016
		md (get_md year)
	]
	(printf "%02d.%02d.%04d" (last md) (inc (first md)) year )

)

clojure2

(import java.util.GregorianCalendar
	java.text.DateFormatSymbols)
 
(->> (for [year (range 1900 2101)
	   month [0 2 4 6 7 9 11] ;; 31 day months
	   :let [cal (GregorianCalendar. year month 1)
		 day (.get cal GregorianCalendar/DAY_OF_WEEK)]
	   :when (= day GregorianCalendar/FRIDAY)]
       (println month "-" year))
     count
     (println "Total Months: " ,))

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.