Clojure学习笔记

Clojure是一门基于JVM的LISP方言, 为了LISP而学习。 在跟这篇文章起名的时候,考虑将其放在JAVA大类下, 不过一门语言最重要的应该是思想吧, 遂将其放在LISP的大类下。

这只是一个简单的笔记, 原文点击这里.

Reader

Macro characters宏

reader的行为是由一系列built-in的结构与被称为read table的拓展系统。整个read table有被称为宏的字符进行索引。

Quote(‘)

'form ===> (quote form)

Character(\)

like \newline, \space, \tab

Comment(;)

Deref(@)

@form ===> (deref form)

Metadata(^)

元数据学习

Dispatch(#)

这个宏会使reader从另一个表出去。

#{} 集合, 阅读上面的集合

正则模式 (#”pattern”)

变量quote(#’) 例如 #’x ===> (var x)

匿名函数

#(...) ===> (fn [args] (...))

忽略下一个form(#_)

Syntax-quote语义引用

`, note, “backquote” 字符. unquote(~) (unquote-splicing ~@)

除了字符, vectors, sets, maps。 `x 与 ‘x相同.

extensible data notation(edn)

under active development

The REPL and main entry points

reference过于抽象, 这里换个教程

Essentials

Clojure语言基础

表达式, 标识符(locals, vars)

let forms

scalars

functions

基础的数据类型

引入不可变的数据结构

Clojure的reference 类型概述

循环与递归

基本的Clojure宏

Scalars

nil, true, false

Data Structures

[1 2 3] ; A vector

[1 :two "three"] ; Put anyting into them you like.

[:a 1 :b 2] ; A hasmap

#{:a :b :c} ; A set (unorderd, and contains no duplicates)

'(1 2 3) ; A list (linked-list)

Abstractions

Clojure的一些抽象:

Collection (Lists, vectors, maps, and sets are all collections)

Sequential (Lists and vectors are ordered collections)

Associative (Hashmaps associate keys with values)

Indexed

宏与特殊的Forms

如何一个表达式开始一个开放的括号, Clojure首先检查是否为一个宏或者特殊form. 这些特殊的forms并不遵循估值规则, 被特殊对待。

宏的调用在编译时期被打开, 准确来说, 是在你的代码被编译之前。 不过Clojurede的内置特殊form(let, def, and if)被硬编码在编译器中。 而不是被定义为宏。 此处不再说明宏。

流程控制

Functions: Defining Your Own

You can create a function using fn, and give it a name using def:

(def my-func

(fn [a b]

(println "adding them!")

(+ a b)))

Language Guides

函数

定义函数

调用函数

Multi-arity

可变函数

Higher order函数

其他相关技巧

定义函数

(defn round

[d precision]

(let [factor (Math/pow 10 precision)]

(/ (Math/floor (* d factor)) factor)))

(defn round

"Round down a double to the given precision (number of significant digits)"

[d precision]

(let [factor (Math/pow 10 precision)]

(/ (Math/floor (* d factor)) factor)))

匿名函数

匿名函数使用fn特殊form进行定义

(let [f (fn [x]

(* 2 x))]

(map f (range 0 10)))

(let [f #(* 2 %)]

(map f (range 0 10)))

Multi-arity 函数

(defn tax-amount

([amount]

(tax-amount amount 35))

([amount rate]

(Math/round (double (* amount (/ rate 100))))))

Overview of clojure.core, the standard Clojure library

Binding

let

Let bindings are immutable and can be destructured.

(let [bindings*] expres*)

(let [x 1]

(println x) ; prints 1

(let [x 2]

(println x))) ; prints 2

def

(def symbol doc-string? init?)

declare

forward declarations. defs the supplied symbols with no init values.

([& names])

defn

([name doc-string? attr-map? [params*] prepost-map? body] [name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?])

(def func (fn [x] x))

;; same as:

(defn func [x]

x)

;; with metadata added by defn

(def ^{:doc "documentation!"} ^{:arglists '([x])} func (fn [x] x))

;;same as

(defn func

"documentation!"

[x]

x)

Branching

if

(if test then else?)

(if (nil? (= 1 2)) "second" "third") ; differentiate between nil and false if needed

when

([test & body])

Looping

recur

recur 接受一定数量的indentical的递归点。

(recur exprs*)

(defn count-up

[result x y]

(if (= x y)

result

(recur (conj result x) (inc x) y)))

;; ⇒ [0 1 2 3 4 5 6 7 8 9]

loop

多了一个Let

(loop [bindings*] exprs*)

(defn count-up

[start total]

(loop [result []

x start

y total]

(if (= x y)

result

(recur (conj result x) (inc x) y))))

;; ⇒ [0 1 2 3 4 5 6 7 8 9]

集合与队列的修改

conj

(conj '(1 2) 3)

;; ==> (3 1 2)

(conj [1 2] 3)

;; ==> [1 2 3]

(conj {:a 1 :b 2 :c 3} [:d 4])

;; ==> {:d 4, :a 1 :b 2 :c 3}

(conj #{1 4} 5)

;; ==> #{1 4 5}

(conj #{:a :b :c} :b :c :d :e)

;; ==> #{:a :b :c :d :e}

empty

(empty [1 2 3])

;; ==> []

(empty {:a 1 :b 2 :c 3})

;; ==> {}

assoc

dissoc

都是跟map有关的

集合或队列的信息

count

(count "Hello")

;; ==> 5

(count [1 2 3 4 5 6 7])

;; ⇒ 7

(count nil)

;; ⇒ 0

empty? 是否为空

not-empty

集合或队列中的元素

first

rest

get

contains?

keys

vals

take

filter

(filter even? (range 10))

操作集合和队列

函数组合与应用

juxt

与java交互

木纹标识lisp_lisp_clojure.org相关推荐

  1. 木纹标识lisp_Lisp

    LISP - 运算符 运算符是一个符号,它告诉编译器执行特定的数学或逻辑操作. LISP允许在众多的数据业务,通过各种函数,宏和其他结构的支持. 允许对数据的操作都可以归类为: 算术运算 比较操作 逻 ...

  2. 木纹标识lisp_lisp:关于标识符:原子和列表初步

    在任何的高级语言里面都需要标识符这么一个东西,从本质上来讲,标识符体现了数学中的方程的思想--对于计算机来说,标识符中所包含的数据是未知的,需要 从终端输入 的.因此他是个并不新鲜的东西,你只要编程就 ...

  3. 木纹标识lisp_LISP架构中一种新的移动性管理方案研究

    1 前 言 近年来,互联网在基础架构方面暴露出越来越多的问题,BGP路由表的增长问题更是被提入IETF工作日程.根据互联网结构委员会IAB(Internet Architecture Board)的报 ...

  4. 木纹标识lisp_AutoLisp学习笔记:变量类型

    关于变量的几个概念: 1.符号 符号(SYMBOL)可以理解为标识,用来作为变量.函数的名字.它的命名规则是不能只含数字,可以由下列字符以外的任何可打印的字符所组成: "(".&q ...

  5. 木纹标识lisp_Visual-LISP程序设计(第2版)第6章调试程序.ppt

    ⑥ FILE(文件) 文件的检验窗口见图6-24.元素表内是该文件的名字和打开该文件时的属性.name指出了文件名,mode指出该文件是打开供读.写.附加,还是已被关闭,id是内部的文件标识,posi ...

  6. 木纹标识lisp_lisp 习题 用列表元素标识文件一行。

    定义一个函数,接受一个文件名并返回一个由字串组成的列表,来表示文件里的每一行 CL-USER> (defun pseudo-cat (file) (with-open-file (str fil ...

  7. 木纹标识lisp_Lisp 中的 string 和 symbol 的区别?

    感觉大家都没说到点子上, 定义:Symbol(符号)只是用来指代能够引用其他数据类型的一种数据类型而已. 通常情况下,Symbol在read时读为符号(这个数据类型),然后在eval时(根据上下文)求 ...

  8. 高精地图中导航标识识别

    高精地图中导航标识识别 思路 主要介绍高精地图导航标识识别上的技术演进,这些技术手段在不同时期服务了高精地图产线需求. 高精地图介绍 当你开车导航的时候,导航地图会向我们推荐一条或几条路线,有些地图甚 ...

  9. SQL Server中Identity标识列

    SQL Server中,经常会用到Identity标识列,这种自增长的字段操作起来的确是比较方便.但它有时还会带来一些麻烦. SQL Server中,经常会用到Identity标识列,这种自增长的字段 ...

最新文章

  1. Linux 的无障碍设置如何操作?
  2. Adam又要“退休”了?耶鲁大学团队提出AdaBelief,NeurIPS 2020收录,却引来网友质疑...
  3. ML之Kmeans:利用自定义Kmeans函数实现对多个坐标点(自定义四个点)进行自动(最多迭代10次)分类
  4. NET Core微服务之路:再谈分布式系统中一致性问题分析
  5. statusbar 尺寸 显示图标_移动端页面设计规范尺寸大起底 - 椰树飘香
  6. 一步步编写操作系统 59 cpu的IO特权级1
  7. C++学习之路 | PTA乙级—— 1074 宇宙无敌加法器 (20 分)(精简)
  8. 史上最全面的程序员招聘建议
  9. npoi 未将对象引用设置到对象的实例_new一个对象到底占了多少内存?
  10. mysql explain select_type
  11. C/C++深度分析(二)
  12. libyuv 海思平台编译测试
  13. 地图制作:Google Earth Pro的下载及功能介绍(详细介绍)(上)
  14. word表格跨页断行不起作用
  15. MRT工具谢幕,HEG华丽登场
  16. see into/see off/seek to等动词词组
  17. 支付宝小程序生态服务商奖励发布,单个商家最高奖励5000元
  18. android media rw,Android中的“/ storage/udisk/sda4 /”和“/ mnt/media_rw/udisk/sda4 /”有什么区别?...
  19. 微软原版系统安装Win7篇
  20. spring 定时器时间配置

热门文章

  1. “棱镜”入侵手机App, 爱加密有效防窃听
  2. SAP HANA XS ODATA使用参数展示具体数据
  3. linux中如何压缩目录文件,如何在Linux中压缩和解压缩目录及其文件
  4. 游戏设计的艺术和技术
  5. 大自然是最广阔的“感统训练室”,端午节带上孩子“趣”玩吧!
  6. 数据库系统学习笔记(3)
  7. vb计算机怎么制作,教你如何制作VB的PCode调试器 -电脑资料
  8. 算法- C语言实现侏儒(地精)排序(Gnome_sort)
  9. 机械硬盘无法访问要怎么办啊
  10. 如何优雅地使用 Sublime Text