Giter VIP home page Giter VIP logo

clojure.coffee-js.org's People

Contributors

tiye avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

marquisthunder

clojure.coffee-js.org's Issues

应该怎样理解 clj 中的命名空间概念?

命名空间概念好难.. 断断续续看了文档还是不懂, 我把进度在这里整理了

首先 Google Code 上说明写的很清晰: http://code.google.com/p/clojure-doc-en2ch/wiki/Chapter_7
REPL 默认的 ns 是 user, user 中含有 clojure.core, 新创建的 ns 里不一定有
默认的 clojure 对象是从所有的 ns 可以访问的

可以通过 *ns* 来查看, 使用 in-ns 可以切换命名空间:

user=> *ns*
#<Namespace user>
user=> (in-ns 'greetings)
#<Namespace greetings>
greetings=> clojure.core/*ns*
#<Namespace greetings>
greetings=> (clojure.core/println "Hello, World!")
Hello, World!
nil

问题是命名空间相互间意义是什么, 怎样相互引用, 主入口怎样来?
clojure.core/println 中的 / 表示引用一个 ns, 但是点号是什么?

referalias 只是从已有的模块里导入引用, 理解目前没问题

greetings=> map
java.lang.Exception: Unable to resolve symbol: map in this context (NO_SOURCE_FILE:0)
greetings=> (clojure.core/refer 'clojure.core :only '(map set))
nil
greetings=> map
#<core$map clojure.core$map@41a68961>

greetings=> (alias 'core 'clojure.core)
nil
greetings=> (core/println "s")
s
nil

load 也是, 从文件加载模块是习见的, 我在 REPL 对应目录新建 lib.clj

(defn f [x] (println x))

然后在 REPL 运行代码就把文件给引入了:

greetings=> (load-file "./lib.clj")
#'greetings/f
greetings=> (f "x")
x
nil

require 是相对更高级的接口, 我创建了 example/lib.clj 文件如下:

(defn g [] (println "inside"))

就能从 REPL 中将其引用成功..

greetings=> (require 'example.lib)
nil
greetings=> (g)
inside
nil
greetings=> (require '(example/lib))
nil

但是很古怪的是, 其中一直写法有报错, 甚至 use 语法一起报错

greetings=> (require '[example.lib :as lib])
java.lang.Exception: namespace 'example.lib' not found (NO_SOURCE_FILE:0)

而通过 import 导入 Java 对象又是很好懂的了

greetings=> (import 'java.util.Date)
java.util.Date
greetings=> (new Date)
#<Date Sun Nov 04 17:32:40 CST 2012>

参考:
Clojure-JVM上的函数式编程语言(7) 命名空间 作者: R. Mark Volkmann
Huangz/Notes » Clojure » 命名空间
Clojure Handbook 2.10 命名空间

用 clj 和 cljs 怎样生成静态页面, 大家有什么方案?

故伎重施, 打算在现在这个 repo 上收集资源和展开聊天, 用收集资源
Clojure 没有那么多命令行可用来做 HTML 模板, 诶的想法是用 Clojure 生成了直接写了
然后页面的交互尝试用 cljs 做, 那样整个 repo 都能用 Clojure 相关的技术进行维护

蛋疼的是我早开始看 Clojure 但由于其门槛和 lein 工具的麻烦我从来没用在代码当中过
我不相信 Clojure 是最好的语言, 但 Clojure 和 Node 一样会是融汇贯通不同语言的关键
另外也会是很便利的工具, Node 是客户端方面, Clojure 是服务器应用方面

我初步的设想是找一个 HTML 模板, 生成 HTML 写入文件, 再学会 cljs 的基础..
还不知道行不行的通

我现在刚弄明白在 project.clj 里先 :main 能运行 core/ 下的文件.. 比较狼狈

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.