Clojure
zhangningboo
这个作者很懒,什么都没留下…
展开
-
Clojure编程乐趣:多态和表达式
(defprotocol Connectable (my-cat [this other]))=> Connectable#_ 扩展 List 类型(extend-type java.util.List Connectable (my-cat [this other] (println "List my-cat") (concat this other)))=> nil(my-cat [1 2 3] [4 5 6])List my-cat=> (1原创 2021-10-27 15:47:06 · 168 阅读 · 0 评论 -
Clojure创建网站系列一(路由):使用Reitit替换Ring
为什么使用Reitit?嗯~ o(* ̄▽ ̄*)o,因为快!就是因为快!参数解构、参数合法性检查简便,and so on使用lein创建新工程:$ lein new lein-reitit default$ cd lein-reitit补全工程结构:lein-reitit ├─env │ ├─dev │ │ ├─clj │ │ └─resources...原创 2020-04-11 20:24:39 · 647 阅读 · 1 评论 -
牛顿平方根
(defn avg [& args] (/ (apply + args) (count args)))(defn improve [guess x] (avg guess (/ x guess)))(defn good-enough? [guess x] (< (Math/abs (- (* guess guess) x)) 0.001))(defn sqr...原创 2020-03-07 18:02:46 · 160 阅读 · 0 评论 -
Clojure入门
加群:667494487Clojure入门,虽名为入门,但是通篇看了,需要有一点Clojure编码量再回头看看,感觉挺好的,因此去刷题吧,多看看大神们的实现4clojure;通篇文章翻译的还不错,错别字较多,忍受点哈,有些代码跑不通,应该适用于clojure 1,现在用的10,所以不要特别纠结。边看边整理了思维导图,密码:fd50,笔记中附带文中的代码(ps:部分有个人思考),仅供参考...原创 2020-02-26 15:33:27 · 311 阅读 · 0 评论 -
clojure figwheel搭建前端,持续更新
创建前端工程 lein new figwheel your-nameF:\workspace-vscode>lein new figwheel ningdr-front:repositories detected in user-level profiles! [:user]See https://github.com/technomancy/leiningen/wiki/Repe...原创 2020-02-25 22:09:28 · 184 阅读 · 0 评论 -
clojure clara规则引擎example
clojure规则引擎:clara(ns clojure-clara.examples.person (:require [clara.rules.accumulators :as acc] [clara.rules :refer :all]))(defrecord Person [name age sex favorite])(defrecord Filt...原创 2020-02-23 10:51:03 · 319 阅读 · 3 评论 -
clojure小惊喜-持续更新ing...
1、and:elements全为true,返回最后一个element(some #(and (<= 16 (* % %)) %) (range))=> 4(some #(<= 16 (* % %)) (range))=> true(and 1 2)=> 2(and 1 2 false)=> false(and 1 2 false true)...原创 2019-11-23 11:05:29 · 118 阅读 · 0 评论 -
clojure/core sorted-map
点我查看原文及更多示例(ns $clojureDoc.core.sorted-map);; 使用方式:(sorted-map & keyvals);; keyval => key val;; Returns a new sorted map with supplied mappings. If any keys are;; equal, they are handle...原创 2019-06-27 13:52:54 · 125 阅读 · 0 评论 -
clojure/core some
点我查看原文及更多示例(ns $clojureDoc.core.some);; 使用方式:(some pred coll);; Returns the first logical true value of (pred x) for any x in coll,;; else nil. One common idiom is to use a set as pred, for exa...原创 2019-06-27 18:03:24 · 168 阅读 · 0 评论 -
clojure/core slurp
点我查看原文及更多示例(ns $clojureDoc.core.slurp);; 使用方式:(slurp f & opts);; Opens a reader on f and reads all its contents, returning a string.;; See clojure.java.io/reader for a complete list of suppo...原创 2019-06-29 10:16:41 · 274 阅读 · 0 评论 -
clojure/core map-indexed
点我查看原文(ns $clojureDoc.core.map-indexed);; 使用方法:(map-indexed f) (map-indexed f coll);; Returns a lazy sequence consisting of the result of applying f to 0;; and the first item of coll, followed b...原创 2019-06-24 12:38:44 · 204 阅读 · 0 评论 -
clojure/core commute
点我查看原文及更多示例(ns $clojureDoc.core.commute);; 使用方式:(commute ref fun & args);; Must be called in a transaction. Sets the in-transaction-value of;; ref to:;; (apply fun in-transaction-value-of-...原创 2019-06-26 18:58:25 · 164 阅读 · 0 评论 -
clojure/core pcalls
点我查看原文及更多示例(ns $clojureDoc.core.pcalls);; 使用方式:(pcalls & fns);; Executes the no-arg fns in parallel, returning a lazy sequence of;; their values;; 并行执行无参的函数集fns,返回一个由函数执行完后的值组成的惰性序列(def x-...原创 2019-06-26 18:56:25 · 144 阅读 · 0 评论 -
clojure/core future
点我查看原文及更多示例(ns $clojureDoc.core.future);; 使用方式:(future & body);; Takes a body of expressions and yields a future object that will;; invoke the body in another thread, and will cache the resu...原创 2019-06-26 18:27:18 · 208 阅读 · 0 评论 -
clojure/core update-in
点我查看原文及更多示例(ns $clojureDoc.core.update-in);; 使用方法:(update-in m ks f & args);; 'Updates' a value in a nested associative structure, where ks is a;; sequence of keys and f is a function that w...原创 2019-06-23 11:36:21 · 242 阅读 · 0 评论 -
clojure/core atom
点我查看原文及更多示例(ns $clojureDoc.core.atom);; 使用方式:(atom x) (atom x & options);; Creates and returns an Atom with an initial value of x and zero or;; more options (in any order):;; :meta metadat...原创 2019-06-26 15:40:03 · 161 阅读 · 0 评论 -
clojure/core assoc-in
点我查看原文及更多示例(ns $clojureDoc.core.assoc-in);; 使用方式:(assoc-in m [k & ks] v);; Associates a value in a nested associative structure, where ks is a;; sequence of keys and v is the new value and r...原创 2019-06-27 19:22:09 · 259 阅读 · 0 评论 -
leiningen基本操作
创建测试工程:F:\lein-test>lein new compojure lein-test-projectRetrieving compojure/lein-template/0.4.7/lein-template-0.4.7.pom from clojarsRetrieving compojure/lein-template/0.4.7/lein-template-0.4....原创 2019-06-28 15:53:29 · 1216 阅读 · 0 评论 -
clojure/core not-any?
点我查看原文及更多示例(ns $clojureDoc.core.not-any-y);; 使用方式:(not-any? pred coll);; Returns false if (pred x) is logical true for any x in coll, else true.;; 无论coll中存在几个x,只要断言/决策和x运算的返回值为逻辑真,那么not-any?返回假,...原创 2019-07-04 15:39:03 · 130 阅读 · 0 评论 -
clojure/core sequential?
点我查看原文(ns $clojureDoc.core.sequential);; 使用方法 (sequential? coll);; Returns true if coll implements Sequential;; 如果集合实现了Sequential接口,返回 true(sequential? '(1 2 3));; => true(sequential? [1 ...翻译 2019-06-14 12:12:43 · 117 阅读 · 0 评论 -
clojure正整数到二进制转换
(defn get-binary "version:0.1 doc:Transfer a number to a binary format. You need give a positive number or zero, it will return a list which consists of one or zero; You c...原创 2019-09-01 11:29:07 · 263 阅读 · 0 评论 -
clojure/core vec
点我查看原文及更多示例(ns $clojureDoc.core.vec);; 使用方式:;; Creates a new vector containing the contents of coll. Java arrays;; will be aliased and should not be modified.;; 创建一个包含coll元素的新向量;; java数组将被重命名且...原创 2019-07-11 17:03:16 · 174 阅读 · 0 评论 -
clojure/core every?
点我查看原文及更多示例(ns $clojureDoc.core.every-q);; 使用方式:(every? pred coll);; Returns true if (pred x) is logical true for every x in coll, else false.;; 如果coll中的每一项对于断言/决策都为真,则返回逻辑真,否则返回假(println (eve...原创 2019-07-11 16:31:27 · 183 阅读 · 0 评论 -
clojure/core -> vs ->>
点我查看->官方文档及更多示例点我查看->>官方文档及更多示例(ns $clojureDoc.core.sub-big-vs-sub-big-big);; ->;; 使用方式:(-> x & forms);; Threads the expr through the forms. Inserts x as the;; second item ...原创 2019-06-29 12:46:30 · 443 阅读 · 0 评论 -
clojure/core if-let
点我查看原文及更多示例(ns $clojureDoc.core.if-let);; 使用方式:(if-let bindings then) (if-let bindings then else & oldform);; bindings => binding-form test 绑定的形式可以拆分成绑定+表达式;; 比如绑定是这样写:[x (true? true)];;...原创 2019-06-29 11:03:18 · 326 阅读 · 0 评论 -
clojure/core update
点我查看原文及更多示例(ns $clojureDoc.core.update);; 使用方式:(update m k f) (update m k f x) (update m k f x y) (update m k f x y z) (update m k f x y z & more);; 'Updates' a value in an associative struct...原创 2019-06-29 10:44:07 · 297 阅读 · 0 评论 -
clojure/core get-in
点我查看原文及更多示例(ns $clojureDoc.core.get-in);; 使用方式:(get-in m ks) (get-in m ks not-found);; Returns the value in a nested associative structure,;; where ks is a sequence of keys. Returns nil if the k...原创 2019-06-29 09:50:59 · 466 阅读 · 0 评论 -
clojure/core swap!
点我查看原文及更多示例(ns $clojureDoc.core.swap!);; 使用方法:(swap! atom f) (swap! atom f x) (swap! atom f x y) (swap! atom f x y & args);; Atomically swaps the value of atom to be:;; (apply f current-valu...原创 2019-06-26 15:23:18 · 288 阅读 · 0 评论 -
clojure/core lazy-cat
点我查看原文及更多示例(ns $clojureDoc.core.lazy-cat);; 使用方法:(lazy-cat & colls);; Expands to code which yields a lazy sequence of the concatenation;; of the supplied colls. Each coll expr is not evalua...原创 2019-06-26 14:46:24 · 135 阅读 · 0 评论 -
clojure/core zipmap
点我查看原文(ns $clojureDoc.core.zipmap);; 使用方法:(zipmap keys vals);; Returns a map with the keys mapped to the corresponding vals.;; 返回一个map:由keys集合做key,由vals集合做value,keys的数量应该和vals的数量一致(def x (zipma...原创 2019-06-23 00:02:27 · 147 阅读 · 0 评论 -
clojure/core interpose
点我查看原文(ns $clojureDoc.core.interpose);; 使用方法:(interpose sep) (interpose sep coll);; Returns a lazy seq of the elements of coll separated by sep.;; 返回一个元素由sep分隔的一个惰性序列;; Returns a stateful trans...原创 2019-06-20 15:09:48 · 177 阅读 · 0 评论 -
clojure/core reduce
点我查看原文(ns $clojureDoc.core.reduce);; 使用方法:(reduce f coll) (reduce f val coll);; f should be a function of 2 arguments.;; 函数f需要两个参数;; If val is not supplied, returns the result of applying f to...原创 2019-06-20 14:34:05 · 225 阅读 · 0 评论 -
clojure/core reductions
点我查看原文(ns $clojureDoc.core.reductions);; 使用方法:(reductions f coll)(reductions f init coll);; Returns a lazy seq of the intermediate values of the reduction (as per reduce) of coll by f, starting w...原创 2019-06-20 13:03:09 · 122 阅读 · 0 评论 -
clojure/core merge
点我查看原文(ns $clojureDoc.core.merge);; 使用方法:(merge & maps);; Returns a map that consists of the rest of the maps conj-ed onto;; the first. If a key occurs in more than one map, the mapping fro...原创 2019-06-20 12:47:17 · 245 阅读 · 0 评论 -
clojure/core take-while
点我查看原文(ns $clojureDoc.core.take-while);; 使用方法:(take-while pred)(take-while pred coll);; Returns a lazy sequence of successive items from coll while;; (pred item) returns logical true. pred must ...原创 2019-06-20 12:24:14 · 178 阅读 · 0 评论 -
clojure/core iterate
点我查看原文(ns $clojureDoc.core.iterate);; 使用方法 (iterate f x);; Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects;; 返回一个惰性序列:第一项是x,第二项是(f x)的结果,第三项是(f (f x))的结果,即每一次的...原创 2019-06-20 12:04:01 · 141 阅读 · 0 评论 -
clojure/core complement
点我查看原文(ns $clojureDoc.core.complement);; Takes a fn f and returns a fn that takes the same arguments as f,;; has the same effects, if any, and returns the opposite truth value.;; complement接受一个f...原创 2019-06-14 11:55:22 · 145 阅读 · 0 评论 -
clojure/core into
点我查看原文(ns $clojureDoc.core.into);; http://clojuredocs.org/clojure.core/into;; 使用示例 (into) (into to) (into to from) (into to xform from);; Returns a new coll consisting of to-coll with all of th...原创 2019-06-13 18:13:38 · 214 阅读 · 0 评论 -
clojure/core cond(一个宏)
clojure的宏cond,与java 的switch case类似:(ns guestbook.models.clojureCond)(defn clojureCond "cond vs switch case " [arg] (cond (= arg 5) (println "arg equal 5") (= arg 10) (printl...原创 2019-06-13 12:22:28 · 170 阅读 · 0 评论 -
clojure/core apply
点我查看原文(ns $clojureDoc.core.apply);; 使用示例 ([f args] [f x args] [f x y args] [f x y z args] [f a b c d & args]);; apply takes a variable number of arguments and a collection.;; apply接受可变数量的参数和...翻译 2019-06-12 23:49:20 · 226 阅读 · 0 评论