This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-30
Channels
- # aleph (4)
- # beginners (24)
- # boot (15)
- # cider (4)
- # cljs-dev (37)
- # clojure (73)
- # clojure-losangeles (1)
- # clojure-serbia (1)
- # clojure-spec (27)
- # clojurescript (78)
- # core-logic (3)
- # datascript (9)
- # datomic (10)
- # events (1)
- # lein-figwheel (1)
- # lumo (2)
- # off-topic (14)
- # om (6)
- # om-next (1)
- # parinfer (18)
- # pedestal (2)
- # protorepl (4)
- # re-frame (2)
- # reagent (56)
- # specter (6)
- # unrepl (2)
hi beginner with qn - if i defn a function, how do i get the definition itself as a value? like, if i wanted to traverse the code of the function and print out each symbol or something like that
would i have had to quote the fn before i evaluated it? i think i just figured out how to do that
you can try using https://clojuredocs.org/clojure.repl/source
looks like it does a println
, so to get it as data you'd need to wrap it in a https://clojuredocs.org/clojure.core/with-out-str
ah wait, we're in #clojurescript, my bad - to get the js source of a function you can just do (.toString foo)
@fcrick you can google for "syntax-quote"
also the http://clojure.org docs for the reader https://clojure.org/reference/reader
this is kind of blowing my mind
cljs.user=> '`[1]
(cljs.core/vec (cljs.core/sequence (cljs.core/concat (clojure.core/list 1))))
that behavior makes ~@
possible
so how would i make something like
(let [x (list 2 3)] '`[1 ~@x])
not contain x in the result, but only 2 and 3by not using '
+user=> (let [x (list 2 3)] `[1 ~@x])
[1 2 3]
+user=> (let [x (list 2 3)] '`[1 ~@x])
(clojure.core/apply clojure.core/vector (clojure.core/seq (clojure.core/concat (clojure.core/list 1) x)))
i guess what i mean is how would i get something to return the same as this
cljs.user=> '`[1 2 3]
(cljs.core/vec (cljs.core/sequence (cljs.core/concat (clojure.core/list 1) (clojure.core/list 2) (clojure.core/list 3))))
but with the let part still in therecljs.user=> (let [y (let [x (list 2 3)] `[1 ~@x])] `(list ~@y))
(cljs.core/list 1 2 3)
almost đfunnily enough, if i remove the last backtick in that, the browser-based repl i'm playing with crashes
What is a nice way of generating a range of characters in clojurescript? Apparently, \a
doesn't work in cljs
@sbrg I have not used it but this has char-range
https://github.com/daveyarwood/djy
Hi #clojurescript I'm trying to speed-up my library load time by picking a few components at compile time, to make the generated js smaller
I have a macro that calls:
(defn load-def [def-name]
(log/warn "Loading dynamically the Definition:" def-name ", you should recompile catalyst instead.")
(let [p (get name->package def-name)
bot-def (symbol (str p "/raw-rules"))]
(do (require [p])
@(resolve bot-def))))
At compile time I get a Arguments to require must be quoted
@moxaj thanks for taking a look, I get the same error. The full message:
Caused by: clojure.lang.ExceptionInfo: Arguments to require must be quoted. Offending spec: [p] at line 21 src/catalyst/bots/core.cljc {:file "src/catalyst/bots/core.cljc", :line 21, :column 9, :tag :cljs/analysis-error}
@thheller but he's calling require
at compile time, shouldn't that resolve to clojure.core/require
, and thus work?
ah yeah I get it now ⌠you want to emit (require '[some.symbol])
ie. you need the quote
I think that's because (require x)
not quoted will throw when the cljs compiler goes over it
My issue now is that the log
'd or println
'd messages during the macro are output to the compiled js code O.o
I get an unreachable warning now:
Jul 30, 2017 2:13:36 PM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: /target/cljsbuild-compiler-3/cljs/core.js:533: WARNING - unreachable code
}catch (e23214){var e_23219 = e23214;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jul 30, 2017 2:13:36 PM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: /target/cljsbuild-compiler-3/cljs/core.js:586: WARNING - unreachable code
}catch (e23226){var e_23231 = e23226;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jul 30, 2017 2:13:36 PM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 0 error(s), 2 warning(s)
but the compilation is finally going through, I'll keep this one for laterThanks for the help @moxaj and @thheller Here's the version that compiles, if that can help someone:
(ns catalyst.bots.core
(:require [catalyst.core :refer [make]]
...
#?(:cljs (:require-macros [catalyst.bots.core :refer [preload-bots]])))
(def name->package
{:helloworld 'catalyst.bots.bot-001-helloworld
:helloyes 'catalyst.bots.bot-002-helloyes
:whatsyourname 'catalyst.bots.bot-003-whatsyourname
...
})
#?(:clj
(do
(defn load-def [def-name]
(cljs.util/debug-prn "Loading dynamically the Definition:" def-name ", you should recompile catalyst instead.")
(let [p (get name->package def-name)
bot-def (symbol (str p "/raw-rules"))]
(do (clojure.core/require p)
@(resolve bot-def))))
(defmacro preload-bots []
(let [def-name (keyword (System/getenv "REACT_APP_BOT"))
data (load-def def-name)]
(cljs.util/debug-prn "Compiling macro with def-name =" def-name)
(when def-name
`(def preloaded
{~def-name (make ~data)}))))))
(preload-bots)
(defn ^:export rules-for [bot-name]
(let [k-bot-name (keyword bot-name)]
(assert (contains? name->package k-bot-name)
(str "Missing bot:" bot-name))
(get preloaded bot-name)))
be aware that caching will not be aware of (System/getenv "REACT_APP_BOT")
so incremental builds wonât work (if you change it)
@rnagpal Maria Gheller gave general talk on how the compiler operates. http://m.youtube.com/watch?v=Elg17s_nwDg
@rnagpal I think Fogus's article is still relevant http://blog.fogus.me/2012/04/25/the-clojurescript-compilation-pipeline/
@rnagpal Maria Gellerâs talk pretty much covers it - for details I agree with @mfikes, youâll probably just want to read through the analyzer and the compiler sources
Is there a way to call functions on a javascript object that i declared within clojurescript? I'm trying to call a function on a reagent component, but can't figure out how
@mobileink I tried calling the function on the value returned by the reagent function. But it said the function being called didn't exist
@mobileink I'm not near my computer right now :( but do you have any idea how to call it correctly?
nope. đ not really a ninja but have been messing with interop. 1st: check your syntax (.foo bar)
with dot.
Hello fellow Clojurians,
How can I get just the âraw HTML stringâ from an ajax GET request?
(Iâm making a GET request to slurp
. So Iâm instead making an AJAX GET request to welcome-url. (Or is there a simpler way?). When I console-log the response of the GET request, I see the HTML string I want to parse, but the response itself is a Javascript object Object. How can I simply get the âraw HTML stringâ?
(Apologies if this isnât the right place for these kinds of questions?)