- 浏览: 426232 次
- 性别:
- 来自: 上海
-
文章分类
- 全部博客 (118)
- JBPM4 (1)
- JavaScript (11)
- Hibernate (3)
- Spring (2)
- JAVA设计模式 (0)
- JAVA基础 (8)
- JQuery (1)
- Maven (9)
- Ant (1)
- Log (3)
- Linux (13)
- NoSQL (1)
- Emacs (6)
- JAVA (10)
- 道,可道,非常道 (6)
- CSS3 (3)
- HTML5 (1)
- 其他 (3)
- groovy (1)
- Clojure (21)
- ExtJs (3)
- play! (3)
- freemarker (1)
- prolog (3)
- python (2)
- hadoop (1)
- OS X (1)
- JVM (1)
- scala (3)
- 算法 (2)
- play2 (0)
- play2 scala (1)
- play2 java (1)
- android (0)
- xxx (0)
- storm (0)
- go (0)
最新评论
-
yhxf_ie:
Scala真好玩啊
关于scala搞出的新概念和语法糖 -
莴笋的春天:
能解密吗?
MD5算法的一个实现 -
TerrorM-eye:
引用神奇的花括号{}代替小括号()语法那个让我想起了spark ...
关于scala搞出的新概念和语法糖 -
u012896872:
不错,有收获。
关于scala搞出的新概念和语法糖 -
qiaoxiaoka:
我在logback中加了 <logger nam ...
在logback中配置mybatis显示sql
In Clojure 1.2, you can destructure the rest argument just like you would destructure a map. This means you can do named non-positional keyword arguments. Here is an example: user> (defn blah [& {:keys [key1 key2 key3]}] (str key1 key2 key3)) #'user/blah user> (blah :key1 "Hai" :key2 " there" :key3 10) "Hai there10" user> (blah :key1 "Hai" :key2 " there") "Hai there" user> (defn blah [& {:keys [key1 key2 key3] :as everything}] everything) #'user/blah user> (blah :key1 "Hai" :key2 " there") {:key2 " there", :key1 "Hai"} Anything you can do while destructuring a Clojure map can be done in a function's argument list as shown above. Including using :or to define defaults for the arguments like this: user> (defn blah [& {:keys [key1 key2 key3] :or {key3 10}}] (str key1 key2 key3)) #'user/blah user> (blah :key1 "Hai" :key2 " there") "Hai there10" But this is in Clojure 1.2. Alternatively, in older versions, you can do this to simulate the same thing: user> (defn blah [& rest] (let [{:keys [key1 key2 key3] :or {key3 10}} (apply hash-map rest)] (str key1 key2 key3))) #'user/blah user> (blah :key1 "Hai" :key2 " there") "Hai there10" and that works generally the same way. And you can also have positional arguments that come before the keyword arguments: user> (defn blah [x y & {:keys [key1 key2 key3] :or {key3 10}}] (str x y key1 key2 key3)) #'user/blah user> (blah "x" "Y" :key1 "Hai" :key2 " there") "xYHai there10" These are not optional and have to be provided. You can actually destructure the rest argument like you would any Clojure collection. user> (defn blah [& [one two & more]] (str one two "and the rest: " more)) #'user/blah user> (blah 1 2 "ressssssst") "12and the rest: (\"ressssssst\")" You can do this sort of thing even in Clojure 1.1. The map-style destructuring for keyword arguments only came in 1.2 though.
发表评论
-
地图着色——core.logic求解
2015-06-16 13:24 1066记得很久很久之前写过一篇《七周七语言——地图着色》。用core ... -
storm源码阅读——启动脚本一览
2014-12-22 01:29 0testtestst -
storm源码阅读——Nimubs启动
2014-12-12 18:29 0学习使用clojure代码也有一段时间了。除了用clojure ... -
用clojure实现一致性哈希算法(consistent hashing)
2014-05-16 18:42 1478一、依赖的jar包 [com.google.guava/g ... -
关于clojure的gen-class
2014-05-15 12:04 2065关于gen-class的参数说明: :name aname ... -
关于clojure的ns中的require,use,import等
2014-05-15 11:20 2932初学clojure的时候曾经对ns引入库的几个函数疑惑了一阵, ... -
clojure逻辑编程框架——core.logic入门
2014-03-10 00:31 1653core.logic是miniKanren的一个实现。mini ... -
用clojure和javascript看hadoop的map和reduce
2014-01-16 18:28 0(reduce + (map #(* % 2) [1, ... -
lein插件大全
2014-01-08 22:54 3748lein插件的wiki地址:https://github. ... -
什么是闭包
2013-12-26 22:11 87今天有个同事问我什么是闭包? 我脑子里一闪而过匿名函数,内部访 ... -
一张clojure思维导图
2013-12-25 10:19 1091... -
clojure网页爬虫代码阅读
2013-09-10 18:34 0clojure网页爬虫代码: (ns examples.c ... -
一步完成emacs的clojure开发环境配置——emacs-live
2013-08-26 15:49 1891断断续续学习Emacs好久 ... -
clojure解构(clojure destructuring)
2013-06-15 02:17 3893解构是什么? 可以认为map、list、struct等是构造出 ... -
clojure学习——通过ssh2协议远程执行命令
2013-02-19 16:06 8一、添加ganymed-ssh2依赖 (defprojec ... -
Clojure学习——Web框架Noir
2012-12-16 12:25 1882Noir是一个clojure的轻量级的web快速开发框架。而且 ... -
Clojure学习——Protocols & Datatypes
2012-12-08 17:37 0由于java的接口有一定的缺憾,所以 -
Clojure学习——给持久化框架配上c3p0连接池
2012-12-06 17:07 1783之前的两个持久化框架都没有使用连接池。总感觉不放心。试着配置了 ... -
Clojure学习——持久化框架clj-record
2012-12-06 10:47 1603clj-record是仿Ruby on Rails Activ ... -
Clojure学习——持久化框架ClojureQL
2012-12-06 09:35 1669之前写过用clojure jdbc来连接数据库进行操作。对于很 ...
相关推荐
该库提供了对带有可选参数的Clojure函数的改进处理。 该库提供了defn+opts宏,该宏定义了带有可选参数的函数。 语法类似于Clojure的defn之一,只允许使用一个函数体。 支持可选参数的文档字符串。 当defn+opts函数...
可以使用可变参数来定义接受任意数量参数的函数,如 `(defn hello-count [name & args] (str "Hello " name ", you passed " (count args) " extra args"))`。 宏(Macro): Clojure中的宏是用于生成代码的代码,...
- **函数定义**:使用`defn`关键字定义函数,支持匿名函数和高阶函数。 #### 三、函数式编程概念 - **纯函数**:同一组输入始终产生相同输出的函数,不依赖于外部状态,也无副作用。 - **不可变数据**:Clojure中的...
- **高阶函数**: 接受函数作为参数或返回函数作为结果的函数被称为高阶函数。Clojure支持高阶函数,这极大地增强了其灵活性和表达能力。 - **不可变数据**: 在Clojure中,数据一旦创建就无法修改,这对于并发编程尤...
Clojure是一种基于Lisp家族的函数式编程语言,它运行在Java虚拟机(JVM)上,同时也支持JavaScript和其他平台。Clojure的设计目标是提供一个高效、并发、可移植的环境,适合解决现代软件开发中的复杂问题。在这个...
根据提供的文件内容,我们可以提取出以下关于Clojure语言的知识点: Clojure是一种编程语言,它给作者留下了深刻的印象,并且被视为一种多用途的、全面的编程语言。作者在开始学习Clojure时,体会到了编程的乐趣,...
《Clojure电子书》集合包含了三本关于Clojure编程的重要书籍和一个Leiningen的Windows安装程序,这对于学习和深入理解Clojure语言至关重要。Clojure是一种基于Lisp的函数式编程语言,它运行在Java虚拟机(JVM)上,...
[2009] Programming Clojure.(Stuart Halloway).[1934356336].pdf [2010] Functional Programming with Clojure - Simple Concurrency on the JVM.(Tim Berglund, Matthew McCullough).[193650202X].pdf [2010] ...
### 编程Clojure:全面解析与学习指南 #### 一、Clojure语言概述 《Programming Clojure》是一本深入探讨Clojure编程语言的书籍,该书由Stuart Halloway编写,出版于2009年3月,由Pragmatic Bookshelf出版社发行。...
Clear, practical Clojure for the professional programmer Professional Clojure is the experienced developer's guide to functional programming using the Clojure language. Designed specifically to meet ...
Clojure是一种基于Lisp的函数式编程语言,它运行在Java虚拟机(JVM)上,充分利用了Java的生态系统。Clojure的设计目标是提供一种静态类型的、并发的、内存安全的语言,同时保持Lisp的简洁性和灵活性。在这个压缩包...
Clojure的核心理念是函数式编程,这意味着代码被视为数据处理,函数可以作为参数传递,也可以返回新的函数。这与面向对象编程有很大的区别,函数式编程更注重状态不变性和无副作用,有助于编写可预测和易于测试的...
### Clojure 数据分析实战指南 #### 一、书籍概述与背景 《Clojure 数据分析实战指南》是一本针对数据分析师和技术开发人员的实用手册。本书由 Eric Rochester 编写,旨在帮助读者通过超过110个实用案例深入了解...
《Programming Clojure 第三版》是一本深入探讨Clojure编程语言的专业书籍,旨在帮助开发者全面理解和掌握这门基于Lisp的现代函数式编程语言。Clojure是由Rich Hickey设计的,它运行在Java虚拟机(JVM)上,同时也...
[2013] Functional Programming Patterns in Scala and Clojure - Write Lean Programs for the JVM.(Michael Bevilacqua-Linn).[1937785475].pdf+epub.rar [2014] Clojure Cookbook - Recipes for Functional ...