clojurescript

Why clojurescript macros can't be written in clojurescript?

假装没事ソ 提交于 2019-12-04 16:29:34
问题 While clojure and clojurescript features are basically the same (apart from obvious differences), macros are not. When I want a macro in clojurescript I have to write it in clojure and require it with require-macros. Is that a technical limitation of javascript or just a design decision? Why can't both be the same? 回答1: From ClojureScript: Up and Running by Stuart Sierra and Luker VanderHart, page 69: Macros are applied during the compilation process. They do not exist at runtime. Because the

How to catch any Javascript exception in Clojurescript?

我们两清 提交于 2019-12-04 15:39:08
问题 In my communication layer I have a need to be able to catch ANY javascript exception, log it down and proceed as I normally would do. Current syntax for catching exceptions in Clojurescript dictates that I need to specify the type of the exception being caught. I tried to use nil, js/Error, js/object in the catch form and it doesn't catch ANY javascript exception (which can have string as the type of the object). I would appreciate any hints how this can be done natively in Clojurescript. 回答1

ArangoDB Foxx and Clojure script

徘徊边缘 提交于 2019-12-04 12:53:09
I'd like to implement a Foxx service using ClojureScript. I've read that one can use Typescript and Coffeescript by running the transpiler during each development step; Can I do similar for ClojureScript ? As far as we know, it is not possible to write ClojureScript applications in such a way that they could run in ArangoDB/Foxx. Unlike TypeScript and CoffeeScript, ClojureScript is not just a language but an application runtime. It's better to think of it not as an alternative syntax for JavaScript but as a way to write applications that happen to be executed on a JavaScript engine. In other

Enumerate namespaces and dynamically load them in ClojureScript

烈酒焚心 提交于 2019-12-04 10:59:26
This may actually be a bit of an XY-problem , so I'll try to explain what the goal is first. I'm building a ClojureScript application which is composed of a set of Reagent components. It provides a user interface where you can dynamically add or remove UI elements. These UI elements (components) have a certain type. For example a Markdown component is-a Text component. Whenever the user is presented with the option to add Text we list all the components that match the type+ descendants (in this case Markdown, there could be others). The way I've coded it up is as follows. Each component is in

Why aren't NodeList / HtmlCollection seqable?

一笑奈何 提交于 2019-12-04 08:06:55
问题 As a newcomer to Clojurescript it appears to me that every Clojurescript project will have some snippet of code like this: (extend-type js/NodeList ISeqable (-seq [array] (array-seq array 0))) Why isn't this part of the core library? 回答1: You have to think that clojurescript is a compiler to javascript as a language, not only browser JavaScript. You can also use it in other platforms like nodejs or with the QT library where NodeList does not exist (because it is part of the Dom api and not

How can I create a basic ClojureScript Hello World app in Lighttable?

折月煮酒 提交于 2019-12-04 08:06:47
问题 The documentation seems quite sparse in LightTable. I want to create a very bare bones ClojureScript web application in LightTable as a starting point to build on. I have the Instarepl in Clojure working fine, and then I create a new file called dummy.cljs containing the following: (ns dummy) (js/alert "Hello lighttable") How can I run this? Update I have figured this out now, and I will post a video on how todo it as it is quite visual. Update 2 Here is the video: http://www.youtube.com

how to output individual files to a specified directory for cljsbuild

风流意气都作罢 提交于 2019-12-04 07:31:11
Using cljsbuild, I can compile all my .cljs files to one file. However, I wish to be able to pick a directory for output and have each .cljs file compile into its own .js file. How can this be specified? You can use 'multiple build configurations': cljsbuild accepts a vector of configurations for :builds key, each element of which defines rules for compiling separate .js file (more info could be found in lein-cljsbuild README ). Simple example: :cljsbuild {:builds [;; Config for first .js file {:source-paths ["dir-with-cljs-for-first-js"] :compiler {:output-to "dir-for-js/first.js"} ;; Config

ClojureScript: How to add method via prototype to JS Object?

房东的猫 提交于 2019-12-04 07:08:47
I'm trying to add some functionality to an existing JavaScript system. To be then used from JavaScript again (as opposed to within the ClojureScript namespace). Perhaps this isn't possible? Here's a simplification of what I want to do: // JavaScript String.prototype.foo = function() { return "bar"; } # CoffeeScript String::foo = -> "bar" I want to be able to run my script above, and then call it from elsewhere in the code. I've tried messing with extend-type and defprotocol , along with export , but nothing seemed to expose my foo function. It's possible that this was a design decision and

How are Atoms implemented in Clojurescript?

夙愿已清 提交于 2019-12-04 05:53:10
In Clojure to address concurrency issues we can use an atom to write: user=> (def my-atom (atom 0)) #'user/my-atom user=> @my-atom 0 user=> (swap! my-atom inc) 1 user=> @my-atom 1 user=> (swap! my-atom (fn [n] (* (+ n n) 2))) 4 We know that this (in the Clojure implementation) is a wrapper around the Java Atomic object . Interestingly enough, Atoms are replicated in ClojureScript , at a Syntactic level - even though JavaScript runtimes don't have an Atomic reference. My question is, How are Atoms implemented in Clojurescript? Are they just an object Wrapper? llj098 It just returns and assigns

Improve performance of a ClojureScript program

怎甘沉沦 提交于 2019-12-04 03:52:42
I have a ClojureScript program that mainly performs math calculations on collections. It was developed in idiomatic, host-independent Clojure, so it's easy to benchmark it. To my surprise (and contrary to what the answers would suggest to Which is faster, Clojure or ClojureScript (and why)? ), the same code in ClojureScript runs 5-10 times slower than its Clojure equivalent. Here is what I did. I opened a lein repl and a browser repl at http://clojurescript.net/ . Then I tried these snippets in both REPLs. (time (dotimes [x 1000000] (+ 2 8))) (let [coll (list 1 2 3)] (time (dotimes [x 1000000]