- 浏览: 12939 次
- 性别:
- 来自: 潍坊
文章分类
最新评论
-
john813:
我也在学习 Clojure 。 过程中拼凑了几篇相关博客,欢迎 ...
clojure 学习初体会 -
蓝月儿:
初学java者 刚听说还有这个 呵呵
clojure 学习初体会 -
dennis_zane:
heoxsoft 写道如果你也对Clojure感兴趣的话,希望 ...
clojure 学习初体会 -
heoxsoft:
如果你也对Clojure感兴趣的话,希望能和你聊聊!
clojure 学习初体会 -
heoxsoft:
我以前只能说是看过Lisp,Scheme,没有深入的研究,也没 ...
clojure 学习初体会
读练http://groups.google.com/group/clojure/browse_thread/thread/b2df63353b89c27 有感
SLIME 代码,待整理.....
; SLIME 20100404
user> (apply + (map #(let [k (key %) v (val %)] (* v (cost k))) (cookbook :Coffee)))
(2.25 0.25 0.25)
user> (apply + (map #([[k (key %) v (val %)]] (* v (cost k))) (cookbook :Coffee)))
2.75
user> (defn aa [a]
(let [k (key a) v (val a)]
(* v (cost k))))
#'user/aa
user> (apply + (map aa (cookbook :Coffee)))
2.75
user> (map aa (cookbook :Coffee))
(2.25 0.25 0.25)
user> (apply + (map aa (cookbook :Coffee)))
2.75
user> (defn prn-one-menu [key]
(apply + (map aa (cookbook key))))
#'user/prn-one-menu
user> (prn-one-menu :Coffee)
2.75
user> (defn prn-menu []
(map #(prn (val %) ". " (key %)) menu))
; Evaluation aborted.
user> (def menu {:Coffee 1})
#'user/menu
user> (defn prn-menu []
(map #(prn (val %) ". " (key %)) menu))
#'user/prn-menu
user> (prn-menu)
(1 ". " :Coffee
nil)
user> (defn prn-menu []
(map #(prn (val %) (key %)) menu "Cost: ))
#'user/prn-menu
user> (prn-menu)
(1 :Coffee
nil)
user> (defn prn-menu []
(map #(prn (val %) ". " (key %)) menu))
#'user/prn-menu
user> (defn bb [key]
(apply + (map aa (cookbook key)))))
; Evaluation aborted.
user> (defn bb [key]
(apply + (map aa (cookbook key))))
#'user/bb
user> (bb :Coffee)
2.75
user> (defn prn-menu []
(map #(prn (val %) ". " (key %) (bb (key %)) menu))))
; Evaluation aborted.
user> (defn prn-menu []
(map #(prn (val %) ". " (key %) (bb (key %)) menu)))
#'user/prn-menu
user> (prn-menu)
; Evaluation aborted.
user> (defn prn-menu []
(map #(prn (val %) ". " (key %) (bb :Coffee) menu)))
#'user/prn-menu
user> (prn-menu)
; Evaluation aborted.
user> (defn prn-menu []
(map #(prn (val %) ". " (key %) (bb :Coffee) menu)))
#'user/prn-menu
user> (map #(prn (val %) ". " (key %) (bb :Coffee) menu)))
; Evaluation aborted.
user> (map #(prn (val %) ". " (key %) (bb :Coffee) menu))
; Evaluation aborted.
user> (map #(%) menu)
; Evaluation aborted.
user> (map #(key %) menu)
; Evaluation aborted.
user> menu
{:Coffee 1}
user> (map #(key %) menu)
(:Coffee)
user> (map #(prn (key %) (val %)) menu)
(:Coffee 1
nil)
user> (map #(prn (val %) (key %) menu))
; Evaluation aborted.
user> (map #(prn (val %) (key %)) menu)
; Evaluation aborted.
user> (map #(prn (val %) (key %)) (bb (key %)) menu)
(1 :Coffee
nil)
user> (map #(prn (val %) (key %) (bb (key %))) menu)
; Evaluation aborted.
user> (map #(prn (val %) (key %) (bb (key %))) menu)
(1 :Coffee 2.75
nil)
user> (defn prn-menu []
(map #(prn (val %) (key %) (bb (key %))) menu))
#'user/prn-menu
user> (prn-menu)
(1 :Coffee 2.75
nil)
user> (def cookbook {:Coffee {:coffee 3 :sugar 1 :cream 1}
:Decaf-Coffee {:decaf 3 :sugar 1 :cream 1}
:Caffe-Late {:espresso 2 :steamed-milk 1}
:Caffe-Americano {:espresso 3}
:Caffe-Moca {:espresso 1 :coco 1 :steamed-milk 1 :cream 1}
:Cappuccino {:espresso 2 :steamed-milk 1 :formed-milk 1}})
#'user/cookbook
user> (def cost {:coffee 0.75
:decaf 0.75
:sugar 0.25
:cream 0.25
:steamed-milk 0.35
:foamed-milk 0.35
:espresso 1.00
:cocoa 0.90
:whipped-cream 1.00})
#'user/cost
user> (def cookbook {:Coffee {:coffee 3 :sugar 1 :cream 1}
:Decaf-Coffee {:decaf 3 :sugar 1 :cream 1}
:Caffe-Late {:espresso 2 :steamed-milk 1}
:Caffe-Americano {:espresso 3}
:Caffe-Moca {:espresso 1 :cocoa 1 :steamed-milk 1 :cream 1}
:Cappuccino {:espresso 2 :steamed-milk 1 :formed-milk 1}})
#'user/cookbook
user> (def menu {:Coffee 1
:Decaf-Coffee 2
:Caffe-Late 3
:Caffe-Americano 4
:Caffe-Moca 5
:Cappuccino 6})
; Evaluation aborted.
user> (def menu {:Coffee 1
:Decaf-Coffee 2
:Caffe-Late 3
:Caffe-Americano 4
:Caffe-Moca 5
:Cappuccino 6})
#'user/menu
user> (prn-menu)
; Evaluation aborted.
user> (map #(prn (val %) (key %) ((key %))) menu))
; Evaluation aborted.
user> (map #(prn (val %) (key %) ) menu)
; Evaluation aborted.
user> (dorun (map #(prn (val %) (key %) ) menu))
(1 :Coffee
2 :Decaf-Coffee
nil 3 :Caffe-Late
nil 4 :Caffe-Americano
nil 5 :Caffe-Moca
nil 6 :Cappuccino
nil nil)
user> (map #(prn (val %) (key %) ) menu))
; Evaluation aborted.
user> (dorun (map #(prn (val %) (key %) ) menu))
1 :Coffee
2 :Decaf-Coffee
3 :Caffe-Late
4 :Caffe-Americano
5 :Caffe-Moca
6 :Cappuccino
nil
user> (dorun (map #(prn (val %) (key %) (bb (key %)) menu)))
; Evaluation aborted.
user> (defn bb [key]
(apply + (map aa (cookbook key))))
#'user/bb
user> (defn bb [k]
(k))
#'user/bb
user> (dorun (map #(prn (val %) (key %) (key %) menu)))
; Evaluation aborted.
user> (dorun (map #(prn (val %) (key %) (key %)) menu))
; Evaluation aborted.
user> (dorun (map #(prn (val %) (key %) (bb (key %))) menu))
1 :Coffee :Coffee
2 :Decaf-Coffee :Decaf-Coffee
3 :Caffe-Late :Caffe-Late
4 :Caffe-Americano :Caffe-Americano
5 :Caffe-Moca :Caffe-Moca
6 :Cappuccino :Cappuccino
nil
user> (dorun (map #(prn (val %) (key %) (bb (key %))) menu))
; Evaluation aborted.
user> (defn bb [k]
(k))
#'user/bb
user> (dorun (map #(prn (val %) (key %) (bb (key %))) menu))
; Evaluation aborted.
user> (defn bb [key]
(apply + (map aa (cookbook key))))
#'user/bb
user> (dorun (map #(prn (val %) (key %) (bb (key %))) menu))
1 :Coffee 2.75
2 :Decaf-Coffee 2.75
3 :Caffe-Late 2.35
4 :Caffe-Americano 3.0
; Evaluation aborted.
user> (def cookbook {:Coffee {:coffee 3 :sugar 1 :cream 1}
:Decaf-Coffee {:decaf 3 :sugar 1 :cream 1}
:Caffe-Late {:espresso 2 :steamed-milk 1}
:Caffe-Americano {:espresso 3}
:Caffe-Moca {:espresso 1 :cocoa 1 :steamed-milk 1 :cream 1}
:Cappuccino {:espresso 2 :steamed-milk 1 :formed-milk 1}})
#'user/cookbook
user> (dorun (map #(prn (val %) (key %) (bb (key %))) menu))
1 :Coffee 2.75
2 :Decaf-Coffee 2.75
3 :Caffe-Late 2.35
4 :Caffe-Americano 3.0
5 :Caffe-Moca 2.5
; Evaluation aborted.
user> (def cookbook {:Coffee {:coffee 3 :sugar 1 :cream 1}
:Decaf-Coffee {:decaf 3 :sugar 1 :cream 1}
:Caffe-Late {:espresso 2 :steamed-milk 1}
:Caffe-Americano {:espresso 3}
:Caffe-Moca {:espresso 1 :cocoa 1 :steamed-milk 1 :cream 1}
:Cappuccino {:espresso 2 :steamed-milk 1 :foamed-milk 1}})
#'user/cookbook
user> (dorun (map #(prn (val %) (key %) (bb (key %))) menu))
1 :Coffee 2.75
2 :Decaf-Coffee 2.75
3 :Caffe-Late 2.35
4 :Caffe-Americano 3.0
5 :Caffe-Moca 2.5
6 :Cappuccino 2.7
nil
user> (defn bb [key]
(reduce + (map aa (cookbook key))))
#'user/bb
user> (dorun (map #(prn (val %) (key %) (bb (key %))) menu))
1 :Coffee 2.75
2 :Decaf-Coffee 2.75
3 :Caffe-Late 2.35
4 :Caffe-Americano 3.0
5 :Caffe-Moca 2.5
6 :Cappuccino 2.7
nil
user> (doseq [id menu] (prn (key id)))
:Coffee
:Decaf-Coffee
:Caffe-Late
:Caffe-Americano
:Caffe-Moca
:Cappuccino
nil
user> (doseq [name id menu] (prn (key id)))
; Evaluation aborted.
user> (doseq [[name id] menu] (prn (key id)))
; Evaluation aborted.
user> (doseq [menu] (prn)
)
; Evaluation aborted.
user> (doseq [a menu] (prn))
nil
user> (doseq [a menu] (prn a))
[:Coffee 1]
[:Decaf-Coffee 2]
[:Caffe-Late 3]
[:Caffe-Americano 4]
[:Caffe-Moca 5]
[:Cappuccino 6]
nil
user> (doseq [menu] (prn))
; Evaluation aborted.
user> (doseq [name (menu key)] (prn name))
nil
user> (doseq [name (menu key) id (menu val] (prn name))
nil
user> (doseq [[a b] menu] (prn a b))
:Coffee 1
:Decaf-Coffee 2
:Caffe-Late 3
:Caffe-Americano 4
:Caffe-Moca 5
:Cappuccino 6
nil
user> (doseq [[a b] menu] (prn a "," b))
:Coffee "," 1
:Decaf-Coffee "," 2
:Caffe-Late "," 3
:Caffe-Americano "," 4
:Caffe-Moca "," 5
:Cappuccino "," 6
nil
user> (doseq [[name id] menu] (prn (str id "," name)))
"1,:Coffee"
"2,:Decaf-Coffee"
"3,:Caffe-Late"
"4,:Caffe-Americano"
"5,:Caffe-Moca"
"6,:Cappuccino"
nil
user> (doseq [[name id] menu] (prn (str id name)))
"1:Coffee"
"2:Decaf-Coffee"
"3:Caffe-Late"
"4:Caffe-Americano"
"5:Caffe-Moca"
"6:Cappuccino"
nil
user> (doseq [[name id] menu] (prn (str id name (bb name))))
"1:Coffee2.75"
"2:Decaf-Coffee2.75"
"3:Caffe-Late2.35"
"4:Caffe-Americano3.0"
"5:Caffe-Moca2.5"
"6:Cappuccino2.7"
nil
user> (doseq [[name id] menu] (prn (str id name (bb name))))
"1:Coffee2.75"
"2:Decaf-Coffee2.75"
"3:Caffe-Late2.35"
"4:Caffe-Americano3.0"
"5:Caffe-Moca2.5"
"6:Cappuccino2.7"
nil
user> (doseq [[name id] menu]
(prn (str id name ":" (bb name))))
"1:Coffee:2.75"
"2:Decaf-Coffee:2.75"
"3:Caffe-Late:2.35"
"4:Caffe-Americano:3.0"
"5:Caffe-Moca:2.5"
"6:Cappuccino:2.7"
nil
user> (doseq [[name id] menu]
(prn (str id name ":"
(map + #(let [k (key %) v (val %)] (* (cost k) v)) cookbook))))
; Evaluation aborted.
user> (doseq [[name id] menu]
(prn (str id name ":"
(map + #(let [k (key %) v (val %)] (* (cost %) v)) cookbook))))
; Evaluation aborted.
user> (doseq [[name id] menu]
(prn (str id name ":"
(map + #(let [k (key %) v (val %)] (* 1 v)) cookbook))))
; Evaluation aborted.
user> (doseq [[name id] menu]
(prn (str id name ":"
(map + #(let [k (key %) v (val %)] (* 1 v)) cookbook))))
; Evaluation aborted.
user> (doseq [[name id] menu]
(prn (str id name ":"
(map + #(let [k (key %) v (val %)] (* 1 v)) (cookbook name)))))
; Evaluation aborted.
user> (map + #(let [k (key %) v (val %)] (* (cost v))) (cookbook :Coffee))
; Evaluation aborted.
user> (map + #(let [k (key %) v (val %)] (cost k)) (cookbook :Coffee))
{:coffee 3, :sugar 1, :cream 1}
user> (map str #(let [k (key %) v (val %)] (cost k)) (cookbook :Coffee))
; Evaluation aborted.
user> (map str #(let [k (key %) v (val %)] (v)) (cookbook :Coffee))
; Evaluation aborted.
user> (map + #(let [k (key %) v (val %)] (v)) (cookbook :Coffee))
; Evaluation aborted.
user> (map #(let [k (key %) v (val %)] (v)) (cookbook :Coffee))
; Evaluation aborted.
user> (map #(let [k (key %) v (val %)] (v)) (cookbook :Coffee))
; Evaluation aborted.
user> (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook :Coffee))
; Evaluation aborted.
user> (map + (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook :Coffee)))
(2.25 0.25 0.25)
user> (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook :Coffee))
; Evaluation aborted.
user> (map + (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook :Coffee)))
(2.25 0.25 0.25)
user> (reduce + (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook :Coffee)))
(2.25 0.25 0.25)
user> (reduce + (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook :Coffee)))
2.75
user> (reduce + (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook :Coffee)))
2.75
user> (doseq [[name id] menu]
(println (str id ", " name ","
(reduce + (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook name))))))
1, :Coffee,2.75
2, :Decaf-Coffee,2.75
3, :Caffe-Late,2.35
4, :Caffe-Americano,3.0
5, :Caffe-Moca,2.5
6, :Cappuccino,2.7
nil
user> (doseq [[name id] menu]
(println (str id "," name ","
(reduce + (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook name))))))
1,:Coffee,2.75
2,:Decaf-Coffee,2.75
3,:Caffe-Late,2.35
4,:Caffe-Americano,3.0
5,:Caffe-Moca,2.5
6,:Cappuccino,2.7
nil
user> (doseq [[name id] menu]
(println (str id name ":"
(reduce + (map #(let [k (key %) v (val %)] (* (cost k) v)) (cookbook name))))))
1:Coffee:2.75
2:Decaf-Coffee:2.75
3:Caffe-Late:2.35
4:Caffe-Americano:3.0
5:Caffe-Moca:2.5
6:Cappuccino:2.7
nil
user> (name :Coffee)
"Coffee"
user> (doseq [[name id] menu]
(println (str id name ":"
(reduce + (map (fn [[k v]] (* (cost k) v)) (cookbook name))))))
1:Coffee:2.75
2:Decaf-Coffee:2.75
3:Caffe-Late:2.35
4:Caffe-Americano:3.0
5:Caffe-Moca:2.5
6:Cappuccino:2.7
nil
user>
发表评论
-
Destructuring binding in def
2010-10-31 22:20 846原始链接:http://clojure101.blogsp ... -
揭秘 Compojure – Part 3
2010-08-20 23:03 1383揭秘 Compojure – Part 3 在第 ... -
Mirah --- Ruby in Javanese
2010-08-04 21:23 899Mirah, 刚刚看到的一门新的语言,号称Javanes ... -
clojure 学习初体会
2010-07-25 08:48 4616学习clojure已有数月,总感觉那个地方不太对劲。原先看c ... -
Clojure 学习笔记之when-not
2010-07-25 08:05 1241在clojure中有if 但是没有unless,但是有对应的 ...
相关推荐
作业说明该作业由几个作业组成,这些作业与解构隔离地进行。... 该项目包含以下文件: destructuring.js运行脚本如果要运行代码,可以通过在终端中输入以下内容来执行此操作: nodemon destructuring.js
添加一个plugins部分,并将eslint-plugin-destructuring指定为插件。 然后,启用您要使用的所有规则。 推荐配置 该插件会导出recommended配置,以强制执行所有规则。 您可以如下配置插件: { " plugins " : [ " ...
前端开源库-babel-plugin-extensible-destructuringBabel插件可扩展销毁,Babel插件可根据https://github.com/vacuumlabs/es-proposals启用可扩展销毁
> var compile = require ( 'es6-destructuring' ) . compile ; [ Function ] > compile ( 'var {x, y} = z;' ) . code ; 'var x = z.x, y = z.y;' 命令行 如果通过npm安装,将提供一个名为es6-destructuring的...
标题 "springboard_10-05_destructuring" 暗示了我们即将探讨的是关于编程中的解构赋值(Destructuring)概念,可能是针对JavaScript或者某种支持类似语法的编程语言。解构赋值是一种从数组或对象中提取值,并直接...
作业说明 该作业由几个作业组成,这些作业与解构隔离地进行。 要创建分配,您可以克隆分配或将其下载到您自己的计算机上。 该项目包含以下文件: destructuring.js ... nodemon destructuring.js
【CSharp 编写的人品测试器】 CSharp是一种基于.NET框架的编程语言,以其简洁、类型安全和面向对象的特点而被广泛应用于各种软件开发,包括桌面应用、Web应用以及游戏开发等。在这个项目中,"人品测试器"是一个用...
在CodeSandbox上,你可以创建一个新的项目,导入相关文件(如`ES6-Destructuring-Assigment-master`中的文件),然后逐步实现和测试上述解构赋值的示例。这样不仅可以加深理解,还能实际操作,体验解构赋值带来的...
JavaScript中的解构赋值(Destructuring Assignment)是ES6引入的一种强大且便捷的语法特性,它允许我们从数组或对象中提取数据,并将其赋值给新的变量。在这个"JavaScript_Destructuring_Predictions"练习中,我们...
解构赋值是ES6引入的一种强大的语法特性,它使得从数组或对象中提取值变得更加简洁,大大简化了代码。本文将深入探讨解构赋值的各个方面,包括数组和对象的解构,以及它们在不同场景下的应用。 ...
销毁分配 学习目标 使用解构分配将数据分配给变量 介绍 作为开发人员,有时我们会在集合(例如Object )中接收信息,并且我们想从集合中“挑选”元素。 将每个属性/值对分别从Object提取出来,然后将其分配给变量是...
销毁分配 学习目标 使用解构分配将数据分配给变量 介绍 作为开发人员,有时我们会在集合(例如Object )中接收信息,并且我们想从集合中“挑选”元素。 将每个属性/值对分别从一个Object提取出来,然后将其分配给一...
销毁分配 学习目标 使用解构分配将数据分配给变量 介绍 作为开发人员,有时我们会在集合(例如Object )中接收信息,并且我们想从集合中“挑选”元素。 将每个属性/值对分别从一个Object提取出来,然后将其分配给一...
现场编码练习面试题 概述 这是一个简单的实时编码挑战 规则” 您应该尝试完成此挑战,而无需查看任何其他资源,例如,谷歌搜索,堆栈溢出,文档或课程资料。 但是,您可以查看项目中的任何文件,包括models.js文件...
【变量的解构赋值】是ES6引入的一种新的语法特性,它极大地简化了变量的声明和赋值,尤其在处理数组和对象时。解构赋值允许我们从数组或对象中提取值,并将这些值分配给一组变量,使得代码更简洁、易读。...
1) ES6 demo Destructuring and TemplateLiteral: AssertionError: # test/demo_test.js:7 assert(`${ alice.name } and ${ bob.name }` === `bob and alice`) | | | | | | | | | | | | | "bob and alice" | | |
Whether you’re writing frontend applications or server side code, the phenomenal features from ES6 and beyond – like the rest operator, generators, destructuring, object literals, arrow functions, ...