查看Leiningen教程中文版的源代码
←
Leiningen教程中文版
跳转到:
导航
、
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== 运行代码 == 配置够了,让我们看看代码运行。启动一个REPL(读取-求值-打印循环:read-eval-print loop): $ lein repl nREPL server started on port 40612 Welcome to REPL-y! Clojure 1.4.0 Exit: Control+D or (exit) or (quit) Commands: (user/help) Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) (user/sourcery function-name-here) Javadoc: (javadoc java-object-or-class-here) Examples from clojuredocs.org: [clojuredocs or cdoc] (user/clojuredocs name-here) (user/clojuredocs "ns-here" "name-here") user=> REPL是一种你可以输入任意代码运行在项目上下文里的交互式提示。因为我们已经添加了<code>clj-http</code>依赖到<code>:dependencies</code>里,我们就可以从项目的<code>src/</code>目录的<code>my-stuff.core</code>命名空间里加载它: user=> (require 'my-stuff.core) nil user=> (my-stuff.core/-main) Hello, World! nil user=> (require '[clj-http.client :as http]) nil user=> (def response (http/get "http://leiningen.org")) #'user/response user=> (keys response) (:trace-redirects :status :headers :body) 调用<code>-main</code>显示一起打印了输出("Hello, World!")和返回值nil。 通过<code>doc</code>可以使用内置文档,并且<code>clojuredocs</code>提供更全面的例子,来自[http://clojuredocs.org ClojureDocs]站点: user=> (doc reduce) ------------------------- clojure.core/reduce ([f coll] [f val coll]) f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the first 2 items in coll, then applying f to that result and the 3rd item, etc. If coll contains no items, f must accept no arguments as well, and reduce returns the result of calling f with no arguments. If coll has only 1 item, it is returned and f is not called. If val is supplied, returns the result of applying f to val and the first item in coll, then applying f to that result and the 2nd item, etc. If coll contains no items, returns val and f is not called. user=> (user/clojuredocs pprint) Loading clojuredocs-client... ========== vvv Examples ================ user=> (def *map* (zipmap [:a :b :c :d :e] (repeat (zipmap [:a :b :c :d :e] (take 5 (range)))))) #'user/*map* user=> *map* {:e {:e 4, :d 3, :c 2, :b 1, :a 0}, :d {:e 4, :d 3, :c 2, :b 1, :a 0}, :c {:e 4, :d 3, :c 2, :b 1, :a 0}, :b {:e 4, :d 3, :c 2, :b 1, :a 0}, :a {:e 4, :d 3, :c 2, :b 1, :a 0}} user=> (clojure.pprint/pprint *map*) {:e {:e 4, :d 3, :c 2, :b 1, :a 0}, :d {:e 4, :d 3, :c 2, :b 1, :a 0}, :c {:e 4, :d 3, :c 2, :b 1, :a 0}, :b {:e 4, :d 3, :c 2, :b 1, :a 0}, :a {:e 4, :d 3, :c 2, :b 1, :a 0}} nil ========== ^^^ Examples ================ 1 example found for clojure.pprint/pprint 你甚至能查看函数的源码: user=> (source my-stuff.core/-main) (defn -main "I don't do a whole lot." [& args] (println "Hello, World!")) user=> ; use control+d to exit 如果已经编写了<code>-main</code>函数的代码等待执行,你并不需要交互式地键入代码,执行<code>run</code>任务更简单: $ lein run -m my-stuff.core Hello, World! 提供替代的<code>-m</code>参数来告诉Leiningen在另一个命名空间里查找<code>-main</code>函数。设置project.clj里默认的<code>:main</code>关键字,可以让你省略<code>-m</code>参数。 对于长时间运行的<code>lein run</code>进程,可能你希望利用高阶的trampoline任务来节省内存,它允许Leiningen的JVM进程在启动项目的JVM之前退出。(译注,可以通过lein help trampoline来查看任务的详细说明): $ lein trampoline run -m my-stuff.server 5000
返回到
Leiningen教程中文版
。
个人工具
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面