clojurescript

How can I run eval in ClojureScript with access to the namespace that is calling the eval?

∥☆過路亽.° 提交于 2019-12-12 21:41:07
问题 I have a library of functions which I want to let users play with in the browser. So I want to set up a situation like this : I'm developing with figwheel and devcards. In the main core.cljs I require various functions from my library, so they're all in scope. Now I want to let the user enter some code which calls that library. I see how I can run that code with eval, but I can't see how to make my library functions visible to the code being evaled. And I'm confused by most of the

How can I make functions available to ClojureScript's eval?

给你一囗甜甜゛ 提交于 2019-12-12 20:03:32
问题 In this blog post by Dmitri Sotnikov a function eval-str is provided for running a string containing ClojureScript: (defn eval-str [s] (eval (empty-state) (read-string s) {:eval js-eval :source-map true :context :expr} (fn [result] result))) If I have some function x that I want to be able to call from inside the eval string, how can I do that? 回答1: There are two parts to the answer, assuming x is a var associated with a ClojureScript function: The compiler analysis metadata for x needs to be

How to compare event count value with previous time interval event

蹲街弑〆低调 提交于 2019-12-12 18:12:02
问题 I am looking for whether I can compare the total number of event count for the current one hr interval with the total number of event count with the previous one hour interval and if the current hour count is less than previous hour count then one email should get triggered from Riemann . I am not sure whether we can store the value and compare it with the current event value because I learned events will get expired due to TTL option in Riemann. Please correct me if I am wrong and suggest me

Is there a lib for manipulating CSS on the client side in Clojurescript?

北城以北 提交于 2019-12-12 18:04:28
问题 I want to make new CSS rules on the client, for doing CSS transitions for example. Apparently jQuery has this kind of thing, but what about in the world of Clojurescript ? I found Gaka and Garden for generating CSS on the server side like Hiccup, but what if I want to do dynamic CSS on the client side ? Does Enlive, Dommy or any of those Clojurescript libs do that ? 回答1: Take a look at jayq You can do CSS manipulation to a DOM element via simple built in css wrapper and a Clojure map: (ns

how would a loop with a nested return be implemented in clojure?

一曲冷凌霜 提交于 2019-12-12 14:06:47
问题 I'm playing around with a crafty tutorial here: http://buildnewgames.com/introduction-to-crafty/ and am wondering how this particular function be implemented in clojurescript/clojure var max_villages = 5; for (var x = 0; x < Game.map_grid.width; x++) { for (var y = 0; y < Game.map_grid.height; y++) { if (Math.random() < 0.02) { Crafty.e('Village').at(x, y); if (Crafty('Village').length >= max_villages) { return; } } } } I know that we can have the (for []) construct but how would you get it

depth first tree traversal accumulation in clojure

拈花ヽ惹草 提交于 2019-12-12 14:05:44
问题 I'd like to take a tree-like structure like this: {"foo" {"bar" "1" "baz" "2"}} and recursively traverse while remembering the path from the root in order to produce something like this: ["foo/bar/1", "foo/baz/2"] Any suggestions on how this can be done without zippers or clojure.walk? 回答1: As nberger does, we separate enumerating the paths from presenting them as strings. Enumeration The function (defn paths [x] (if (map? x) (mapcat (fn [[k v]] (map #(cons k %) (paths v))) x) [[x]])) ...

Interfacing Clojure and Clojurescript

人盡茶涼 提交于 2019-12-12 13:35:30
问题 I would like to make my existing Clojure libraries usable from clojurescript as well as create new applications which run in both Clojure and Clojurescript. I understand Clojure and Clojurescript have their differences, and that there are metaprogramming solutions such as cljx. But, I have limited my Clojure code to a compatible subset of Clojurescript and I would simply like to call clojure from clojurescript (and possibly vice-versa). I have seen this possible in libraries such as core

stringify/parse edn in clojure/ClojureScript

与世无争的帅哥 提交于 2019-12-12 11:49:56
问题 In JavaScript one can turn a js data structure into a JSON string via JSON.stringify({somedata: { somesubdata: {}}}) And somewhere else, one can parse it again into a JS data structure via var my_obj = JSON.parse("{"somedata":{"some_subdata":{}}}"); What would be the equivalent in Clojure/ClojureScript for the edn format? I want to stringify some data on a ClojureScript front-end and parse it on a Clojure back-end. (and vice versa) 回答1: As pointed out in a comment, a very detailed answer to

No such namespace: clojure.spec.alpha in clojurescript project setup

天涯浪子 提交于 2019-12-12 10:52:18
问题 I am trying to learn clojure.spec . While setting up a clojure project along boot build tool I am getting following error while requiring the clojure.spec.alpha. Compiling ClojureScript... • js/app.js No such namespace: clojure.spec.alpha, could not locate clojure/spec/alpha.cljs, clojure/spec/alpha.cljc, or Closure namespace "clojure.spec.alpha" in f ile src/cljs/flowparser/app.cljs Elapsed time: 0.141 sec My Boot Configuration is as follows: (def +version+ "0.0.1-SNAPSHOT") (def

How To Detect “Enter” Keypress in Reagent?

五迷三道 提交于 2019-12-12 08:24:51
问题 Given the following code: [:input {:type "text" :value (:text @app-state) :on-change (fn [e] (if (= 31 (.-keyCode e)) (println "ENTER") (println "NOT ENTER")))}] How to change the if condition so that enter keypresses can be distinguished from normal keys? All properties in e except target seem to be null. 回答1: that's how to fix it: you should listen to :on-key-press (rather than :on-change ), because "enter" doesn't trigger :on-change event (it obviously doesn't change the text) key code for