clojurescript

How do I set up a clojureScript project to use specs and test the clojure.core functions at runtime?

こ雲淡風輕ζ 提交于 2019-12-10 10:22:11
问题 Clojure 1.9 introduced specs. Functions in the clojure.core library now have specs. How do I set up a clojurescript project to use specs and test the clojure.core functions at runtime? I used the libraries [org.clojure/test.check "0.10.0-alpha2"] and [org.clojure/spec.alpha "0.1.123"] to install specs and the command instrument . It worked to detect problems in functions that I wrote specs. But it didn't detect problems with clojure.core (for instance, map ). Maybe specs do not work with

Clojure RuntimeException - No reader function for tag db/id

ぐ巨炮叔叔 提交于 2019-12-10 07:31:35
问题 What is happening when I get this error in Clojure? java.lang.RuntimeException: No reader function for tag db/id 回答1: Tagged Literals This error message is related to a feature introduced in Clojure 1.7, tagged literals. Tagged literals are a simple means for extending what data types can be represented as literals in Clojure code or EDN data. Clojure ships with readers for two tagged literals, #inst and #uuid allowing literal representations of java.util.Date and java.util.UUID . Support for

How to set up the configuration in Cursive for Clojurescript?

大兔子大兔子 提交于 2019-12-10 03:15:05
问题 Just how to init a new project? How to compile, test and run? Since the cursive user guide says nothing about cljs. 回答1: From the command line use boot or leiningen (also known as lein) to set up your project, then from within IntelliJ go File->Open on the directory for your application and edit the source files that will be collected up in a project for you. An important file to look at is project.clj - that's lein's project file, that IntelliJ will have picked up. Setting up a lein cljs

ClojureScript clojure.set?

笑着哭i 提交于 2019-12-10 02:50:10
问题 How can I use clojure.set in ClojureScript? I always get a error. (def middle-land (set (for [x water-hor y (vec (clojure.set/difference (set (range 0 board-side)) (set water-ver)))] [x y]))) ReferenceError: clojure is not defined 回答1: Seems you need to explicitly require the namespace to be able to use it: ClojureScript:cljs.user> (ns core (:require clojure.set)) ClojureScript:core> (clojure.set/difference #{1 2} #{1 4}) ;=> #{2} 来源: https://stackoverflow.com/questions/21367433/clojurescript

How to use a ReactJS Component with Clojurescipt/Reagent

╄→гoц情女王★ 提交于 2019-12-09 15:59:15
问题 Is it possible to wrap ReactJS components for use with Reagent in Clojurescript? I have read that it is. Can someone provide me with a basic example? Thanks 回答1: Here is my solution for it (I am going to use a React-Bootstrap Panel Component): 1) Include react-bootstrap.min.js in your html. 2) Here is a sample usage of the Panel component: (def PanelComp (. js/ReactBootstrap -Panel)) (defn page [] [:div [:div [PanelComp {:header "Panel heading without title"} "Panel content"]]]) 来源: https:/

Resolve function throws an error in ClojureScript but not Clojure

蹲街弑〆低调 提交于 2019-12-09 02:47:01
问题 The following program works as I expected in Clojure, but throws an error in ClojureScript. I'm wondering if this is a bug or the feature simply isn't available in ClojureScript or if I need to rethink the way I'm attempting to do this instead. Thanks a lot for the help in advance. ; Clojure... (defn foo [x] x) (defn foobee [x] (str (foo x) "bee")) (println ((resolve (symbol (str "foo" "bee"))) "bizzee")) ;=> bizzeebee ; ClojureScript... (defn foo [x] x) (defn foobee [x] (str (foo x) "bee"))

Clojure & ClojureScript: clojure.core/read-string, clojure.edn/read-string and cljs.reader/read-string

拥有回忆 提交于 2019-12-08 23:04:59
问题 I am not clear about the relationship between all these read-string functions. Well, it is clear that clojure.core/read-string can read any serialized string that is output by pr[n] or even print-dup . It is also clear that clojure.edn/read-string does read strings that are formatted according to the EDN specification. However, I am starting with Clojure Script, and it is not clear if cljs.reader/read-string comply with. This question has been triggered by the fact that I had a web service

how to use a complex return object from clojurescript in javascript

喜夏-厌秋 提交于 2019-12-08 00:37:17
问题 I want to write a clojurescript function that returns a complex item like ["foo" "bar"] or (list "foo" "bar") and I want to be able to call this function from javascript and get at the parts of the return value. How can it be done? In my case, the number of items in the vector/list/collection that I'm returning is known beforehand, and the collection should remain ordered. Here's my clojurescript function. I could do something differently here if it made things easier. Just don't know what

In clojure[script], how to return nearest elements between 2 sorted vectors

我与影子孤独终老i 提交于 2019-12-07 20:03:49
问题 In clojure[script] , how to write a function nearest that receives two sorted vectors a , b and returns for each element of a the nearest element of b ? As an example, (nearest [1 2 3 101 102 103] [0 100 1000]); [0 0 0 100 100 100] I would like the solution to be both idiomatic and with good performances: O(n^2) is not acceptable! 回答1: Using a binary search or a sorted-set incurs a O(n*log m) time complexity where n is (count a) and m (count b) . However leveraging the fact that a and b are

how can macros be evaluated using the clojurescript repl

半世苍凉 提交于 2019-12-07 11:17:32
问题 Once the browser is connected to the clojurescript repl, I previously had no way of calling macros from the repl. This is an issue that has put me off clojurescript in the past, preferring using javascript directly. Basically, I felt that the cljs-repl was kinda lame and I was going back to the compile/debug cycle that writing code in clojure was supposed to emancipate us from. Are there any good workarounds/workflows for pushing and testing code in clojurescript? Especially if macros can be