Tutorials Point, posted on 5th Apr, 2018

Clojure Maps dissoc

(ns clojure.examples.example
   (:gen-class))
(defn example []
   (def demokeys (hash-map "z" "1" "b" "2" "a" "3"))
   (println (dissoc demokeys "b")))
(example)

Tutorials Point, posted on 18th Dec, 2017

Clojure *ns*

(ns clojure.examples.example
   (:require [clojure.set :as set])
   (:gen-class))
(defn example []
   (println *ns*))
(example)

Tutorials Point, posted on 11th Dec, 2017

Clojure data.json

(ns clojure.examples.example
   (:require [clojure.data.json :as json])
   (:gen-class))
(defn Example []
   (println (json/write-str {:a 1 :b 2})))
(Example)

Tutorials Point, posted on 11th Dec, 2017

Clojure Example2 dosync

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (def var1 (ref 10))
   (def var2 (ref 20))
   (println @var1 @var2)
   
   (defn change-value [var1 var2 newvalue]
      (dosync
         (alter var1 - newvalue)
         (alter var2 + newvalue)))
   (change-value var1 var2 20)
   (println @var1 @var2))
(Example)

Tutorials Point, posted on 11th Dec, 2017

Clojure example2 dosync

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (def names (ref []))
   
   (defn change [newname]
      (dosync
         (alter names conj newname)))
   (change "John")
   (change "Mark")
   (println @names))
(Example)

Tutorials Point, posted on 11th Dec, 2017

Clojure dosync

(ns clojure.examples.example
   (:gen-class))
(defn Example []
   (def names (ref []))
   (alter names conj "Mark"))
(Example)

Tutorials Point, posted on 11th Dec, 2017

Clojure Example2 Java Built-in Functions

(ns Project
   (:gen-class))
(defn Example []
   (println (.. System getProperties (get "java.version"))))
(Example)

Tutorials Point, posted on 11th Dec, 2017

Clojure Java Built-in Functions

(ns Project
   (:gen-class))
(defn Example []
   (println (. Math PI)))
(Example)

Tutorials Point, posted on 11th Dec, 2017

Clojure Import Command

(ns Project
   (:gen-class))
(import java.util.Stack)
(defn Example []
   (let [stack (Stack.)]
   (.push stack "First Element")
   (.push stack "Second Element")
   (println (first stack))))
(Example)

Tutorials Point, posted on 11th Dec, 2017

Clojure Example2 Creating Java Objects

(ns Project
   (:gen-class))
(defn Example []
   (def my-int(new Integer 1))
   (println (+ 2 my-int)))
(Example)

1 2 3 4 5 6 7 ... 18 Next
Advertisements
Loading...