Clojure

Table of Contents

The documen for clojure is terrible. I like the scheme and common-lisp document better. I simply want to read a well sectioned document containing all things.

Suspend the interest for clojure for now.

1 clojure.core

  • *in*
  • *out*
  • *err*
  • assert

1.1 Namespace

Namespaces are maps that map name to var. Namespace is seperated by dot, similar to java. The recommended format: org.lib.funcgroup.

  • clojure.core/ns: [name docstring? attr-map? references*]
    • set *ns* to name
    • references are same as calling them, except arguments are not quoted
      • (:refer-clojure …)
      • (:require …)
      • (:use …)
      • (:import …)
      • (:load …)
      • (:gen-class)
  • require [& args]: The scope will be available, the functions under them can be called using the scope.
    • load libs, skip already loaded.
    • do not usually use directly, use in ns instead
    • args can be a single symbol, or with options. It recognizes options
      • :as sym: as a symbol. e.g. (require [clojure.walk :as walk])
      • :refer sym-list: the list of symbols inside the lib can be called without the scope. The list can be :all
  • refer [ns-sym &filters]: refer to all public vars of ns into current namespace. Filters:
    • :exclude list-of-symbols
    • :only list-of-symbols
    • :rename map-of-fromsymbol-tosymbol
  • refer-clojure [& filters]: same as (refer 'clojure-core <filters>). clojure-core is refered by default, so this is typically used with exclude filter.
  • use [& args]: do not use after clojure 1.4. Use require with :refer instead
    1. require
    2. refer the lib's namespace
  • import [& import-symbols-or-lists]: as import a java classes and make them usable in their short name in clojure
    • since we have the rest sign &, the arguments are not inside a list, but as multiple arguments for import
    • as the argument name indicates, it can be symbol or list
      • symbol: is the full java class, e.g. java.util.Date
      • list: to save some typing, if importing multiple classes from same namespace: [java.util.concurrent Executors TimeUnit]

2 Type

2.1 Number

2.1.1 Arithmetic

  • +-*/
  • quot
  • rem
  • mod
  • inc
  • dec
  • max
  • min
  • with-precision

2.1.2 Compare

  • =
  • ==
  • not=
  • <, <=, >, >=

2.1.3 Bitwise

  • bit-and
  • bit-or
  • bit-xor
  • bit-flip
  • bit-not
  • bit-clear
  • bit-set
  • bit-shift-right
  • bit-shift-left
  • bit-test

2.1.4 Cast

  • byte
  • short
  • int
  • long
  • float
  • double
  • bigint
  • bigdec
  • num
  • rationalize

2.1.5 Predicate

  • nil?
  • identical?
  • zero?
  • pos?
  • neg?
  • even?
  • odd?

Other

  • number?
  • rational?
  • integer?
  • ratio?
  • decimal?
  • float?

2.1.6 Random

  • rand
  • rand-int

2.2 symbols & keywords

literals for keywords: :kw, :my.ns/kw, ::in-cur-ns

2.3 String

2.3.1 Use

  • count
  • get
  • subs
  • join
  • escape
  • split
  • split-lines
  • replace
  • replace-first
  • reverse
  • index-of
  • last-index-of

2.3.2 Regex

  • #"pattern"
  • re-find
  • re-seq
  • re-matches
  • re-pattern
  • re-matcher
  • re-groups
  • replace
  • replace-first
  • re-quote-replacement

2.3.3 Letter

  • capitalize
  • lower-case
  • upper-case

2.3.4 trim

  • trim
  • trim-newline
  • triml
  • trimr

2.3.5 Predicate

  • string?
  • blank?
  • starts-with?
  • ends-with?
  • includes?

2.3.6 characters

  • literals: \a \newline
  • char
  • char?
  • char-name-string
  • char-escape-string

3 Collections

3.1 Collection

3.1.1 Generic

  • count
  • empty
  • not-empty

3.1.2 ops

  • into
  • conj
  • walk
  • prewalk
  • prewalk-demo
  • prewalk-replace

3.1.3 Predicates

  • distince?
  • empty?
  • every?
  • not-every?
  • some
  • not-any?

3.1.4 Capabilities

  • sequential?
  • associative?
  • sorted?
  • counted?
  • reversible?
  • coll?
  • list?
  • vector?
  • set?
  • map?
  • seq?
  • record?
  • map-entry?

3.2 List

  • list
  • list*
  • first
  • nth
  • peek
  • .indexOf
  • .lastIndexOf
  • cons
  • conj
  • rest
  • pop

3.3 Vector

3.3.1 Create

  • [ ]
  • vector
  • vec
  • vector-of
  • mapv
  • filterv
  • vector-of

3.3.2 Examine

  • nth
  • get
  • peek

Author: Hebi Li

Created: 2017-09-06 Wed 22:50

Validate