我有一个 html 画布,想在上面显示 Quil 草图。大多数 Quil 示例用于defsketch在静态 html 页面上定义的画布上进行绘制。我想在这个试剂组件中的画布上进行操作:
(defn my-component []
(reagent/create-class
{:component-did-mount (fn [this]
(let [canvas (reagent/dom-node this)
width (.-width canvas)
height (.-height canvas)]
(u/log (str "On canvas with width, height: " width " " height))))
:component-will-mount #(u/log "component-will-mount")
:display-name "my-component"
:reagent-render (fn [] [:canvas {:width 400}])}))
(defn graph-panel []
[v-box
:gap "1em"
:children [[my-component]]])
Run Code Online (Sandbox Code Playgroud)
我找到的执行此类操作的最佳文档是here,但我无法完全弄清楚如何进入下一个级别并将其应用到上面的画布。在上面的画布上画一条线的实际代码会很棒。
事实上,静态且始终运行defsketch就可以了 - 困难在于让它访问这种动态类型的画布。
如果无法完成,那么很高兴知道,我将直接使用Processing.js,假设这是下一个最佳想法。
该map函数将接受的是"映射"函数和散列映射.映射函数将接受MapEntry类型的值.这是因为进入的集合(散列图)看起来像这样:{k v k v k v}和MapEntry是这样的:k v.
我似乎无法得到一个{k v k v k v}被退回.我很容易得到([k v] [k v] [k v]).
markdown-clj似乎运行良好但不转换降价表.我明白表格不是降价规范的官方部分.
所以我现在通过CLJSJS 使用Showdown,为此有一个方便的例子,在这里重复:
(defn convert-to-html [markdown]
(let [converter (js/Showdown.converter.)]
(.makeHtml converter markdown)))
Run Code Online (Sandbox Code Playgroud)
从Showdown文档中,您需要做的事情是将表转换为打开选项tables.我将如何在上面的ClojureScript代码中执行此操作?
编辑 请注意,在提出此问题时,上述语法是正确的.但是你现在需要:
(js/showdown.Converter.)
Run Code Online (Sandbox Code Playgroud)
请注意这两个showdown和Converter已经改变了他们的资本.
在Java和Clojure的数学库中,您通常可以找到幂(或指数)函数.在java.lang.Math它是exp.但是我找不到用于查找任何根的泛型函数.在java.lang.Math你可以得到的平方根sqrt,并与立方根cbrt.如果我想找到第4个根怎么办?我正在寻找一个实现或公式.
鉴于:
val personsOpt:Option[List[Person]] = ???
Run Code Online (Sandbox Code Playgroud)
我更喜欢:
persons = personsOpt.fold(List[Person]()){person => person}
Run Code Online (Sandbox Code Playgroud)
对此:
persons = personsOpt.getOrElse(List[Person]())
Run Code Online (Sandbox Code Playgroud)
出于类型安全的原因.例如,这不编译:
persons = personsOpt.fold(Nil){person => person}
Run Code Online (Sandbox Code Playgroud)
是否有一种简单的方法来获得类型安全但没有{person => person}?
编辑:现在具体了解两件事:
getOrElse.例如,这不编译:personsOpt.getOrElse("") Nil是List(),如果无法推断其类型,编译器将要求您明确.因此使用时不会出现类型问题Nil我刚刚找不到这个链接,但是我做错了(错误地)读取了getOrElse比使用fold一个更不安全的类型Option.
我正在做一个减少我想要累积并返回一个向量的地方。这样做时它工作正常:
(reduce
(fn [[res-vec last-rgb] rgb]
(let [calc-res (mu/colour-distance-L2 last-rgb rgb)
accum-results (conj res-vec calc-res)]
[accum-results rgb]))
[]
colour-selections)
Run Code Online (Sandbox Code Playgroud)
但是,当[]参数被遗漏时,我得到Caused by: java.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Long. 发生这种情况是因为colour-distance-L2它被赋予了至少一个java.lang.Long而不是预期的两个向量(两种类型的 向量[r g b]- 红绿蓝)。
这正是我正在做的那种减少。
我不需要使用 3-arity 版本的 reduce,因为它colour-selections的大小总是至少为 2。我只是把它[]作为克服运行时错误的试验和错误的一部分。事实证明,这样做会产生很好的效果。
有什么方法可以在这里使用reduce的2-arity版本吗?
我想将调试消息放入Om Next源.所以我想把它包含在我自己的使用Om Next库的项目中.
Mine和Om Next是两个来源.我把它们放在一起(即将Om Next名称空间复制到一起)到同一个Lein项目中,并从project.clj中注释掉Om Next库:[org.omcljs/om "1.0.0-alpha21"]
这必须是一个天真的方法,因为当我尝试运行生成的项目时,我收到错误消息:Uncaught TypeError: Cannot read property 'call' of undefined来自我的源代码中的这一行:
(def person (om/factory Person {:keyfn :name}))
Run Code Online (Sandbox Code Playgroud)
如何通过此错误消息?或者更一般地说 - 如何使用Om Next以便调试消息可以放在源代码中?
实现这一目标的另一种方法是构建我自己的Om Next源版本.将调试消息放入库中然后构建和安装它并不困难.虽然有点不方便.
我可以访问 repl 并且我有一个uri可以连接的。我如何连接,查看存在哪些实体和属性,查看它们的值,然后向下钻取等等?我只是使用我不必注册的免费版本。
到目前为止,这是我尝试过的:
C:\programs\datomic-free-0.9.5327>.\bin\repl
Clojure 1.6.0
user=> (use '[datomic.api :only [q db] :as d])
nil
user=> (def conn (d/connect "datomic:dev://localhost:4334/somedb"))
IllegalArgumentExceptionInfo :db.error/unsupported-protocol Unsupported protocol :dev datomic.error/arg (error.clj:57)
user=>
user=> (def conn (d/connect "datomic://localhost:4334/somedb"))
IllegalArgumentExceptionInfo :db.error/invalid-db-uri Invalid database URI datomic://localhost:4334/somedb datomic.error/arg (error.clj:57)
user=> (def conn (d/connect "datomic:mem//somedb"))
IllegalArgumentExceptionInfo :db.error/invalid-db-uri Invalid database URI datomic:mem//somedb datomic.error/arg (error.clj:57)
Run Code Online (Sandbox Code Playgroud)
使用 MySql 或 Oracle 数据库,操作员能够(给定正确的密码)列出所有数据库,连接到其中一个数据库,查看其表,然后通过查询其中一个来开始工作。
通过上下文,即使这个数据库('somedb')在'内存中',我仍然希望它存在,因为有一个事务正在运行。然而,交易者有点可疑,因为它是这样的:
C:\programs\datomic-free-0.9.5327>.\bin\transactor .\config\samples\free-transactor-template.properties
Starting datomic:free://localhost:4334/<DB-NAME>, storing data in: data ...
System started datomic:free://localhost:4334/<DB-NAME>, storing data in: data
Run Code Online (Sandbox Code Playgroud)
我对查询应该已启动并正在运行且其中包含值的数据库感到困惑。
在 Clojure 中,很容易从数字中获取数字列表:
user=> (digits 234432)
(2 3 4 4 3 2)
user=> (map type (digits 22))
(java.lang.Long java.lang.Long)
Run Code Online (Sandbox Code Playgroud)
我的问题是如何反过来——如何从数字列表中创建一个数字?
编辑好点,这里是:
(defn digits [n]
(->> n str (map (comp read-string str))))
Run Code Online (Sandbox Code Playgroud)
它来自这里
在这个函数中有可能to-right是nil,在这种情况下函数应该返回false:
(defn has-children? [loc]
(let [to-right (zip/right loc)]
(and to-right (-> to-right zip/node vector?))))
Run Code Online (Sandbox Code Playgroud)
虽然上述工作正常,我怀疑有当返回false更习惯的方法to-right是nil,还以其他方式使用to-right作进一步调查.
我想使用瞬态来创建一个大型数据结构.这是没有瞬态的代码:
(into [] (repeat 10 :a))
;; => [:a :a :a :a :a :a :a :a :a :a]
Run Code Online (Sandbox Code Playgroud)
我天真的尝试是这样的:
(persistent! (into (transient []) (repeat 10 :a)))
Run Code Online (Sandbox Code Playgroud)
我可以通过以下方式获取错误消息:
(into (transient []) (repeat 10 :a))
;; => ClassCastException clojure.lang.PersistentVector$TransientVector cannot be cast to clojure.lang.IPersistentCollection clojure.core/conj--6410 (core.clj:82)
Run Code Online (Sandbox Code Playgroud)
试图使用是不对的repeat?(没有这样的功能repeat!).什么是更好的方法?