# Clojure

WARNING

This page is a draft containing my personal notes on Clojure. I extracted them from the time I was comparing languages.

# Introduction

# FAQ

# How to create a function?

(defn test "test function" [arg] (print arg))

Or by using a lambda function.

(def test "test function" (fn [x] (print arg)))

# How to create datastructure?

(defstruct structname :ref1 :ref2 :refn)

# How to use datastructure?

(struct structname "ref1_value" "ref2_value" "refn_value")

# How to use a map datastructure?

(map (fn [x] (+ 1 x)) [1 2 3])

# How to use reduce?

(reduce (fn [x y] (+ x y)) [1 2 3 4])

# How to use list comprehension?

# How to define types?

# How to create agents?

(agent [:state])
(def myagent [:state])

# How to call an agent?

(send myagent action)

Another solution is to use send-off function.

(send-off myagent action)

# What can I do if my agent is dead?

    (restart-agent myagent [:state])

# How to use pattern matching?

core.match module is required. You can use by using adding it in the requirement.

[org.clojure/core.match "0.3.0-alpha4"]

Next, use require.

(require '[clojure.core.match :refer [match]])
  • https://github.com/clojure/core.match
  • https://github.com/clojure/core.match/wiki/Understanding-the-algorithm

# How to use deps.edn file?

# References and Resources

  • https://clojure.github.io/clojure/
  • http://clojure-doc.org/
  • https://clojuredocs.org/
  • http://clojure.org/api/api
  • http://github.com/clojure/clojure/
  • http://clojure.org/api/cheatsheet