This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-07-21
Channels
- # aws (2)
- # bangalore-clj (14)
- # beginners (20)
- # boot (20)
- # cider (7)
- # cljs-dev (38)
- # cljsrn (13)
- # clojure (487)
- # clojure-argentina (3)
- # clojure-dev (15)
- # clojure-gamedev (4)
- # clojure-italy (3)
- # clojure-poland (1)
- # clojure-russia (1)
- # clojure-spec (25)
- # clojure-uk (47)
- # clojurescript (127)
- # datomic (125)
- # defnpodcast (1)
- # hoplon (27)
- # jobs (4)
- # lein-figwheel (2)
- # leiningen (1)
- # luminus (5)
- # off-topic (3)
- # om (25)
- # onyx (9)
- # parinfer (3)
- # pedestal (20)
- # planck (65)
- # re-frame (43)
- # reagent (4)
- # remote-jobs (1)
- # ring-swagger (2)
- # rum (9)
- # spacemacs (1)
- # unrepl (37)
- # vim (1)
@chalcidfly Normally, the entire form is first transpiled to JavaScript. I suspect you could first run the analyzer, get the AST, extract the subform, and evaluate that in a target JavaScript environment, and replace it to form a new form.
For your particular example, a tricky bit is the fact that *
is a macro, so macroexpansion will also come into play
The easiest way to see what the analyzer produces, IMHO, is to fire up Lumo or Planck, and evaluate (cljs.js/analyze-str (cljs.js/empty-state) "(+ 2 (* 5 5))" nil {:eval cljs.js/js-eval :context :expr} identity)
@mfikes thanks for the reply — I’m not quite sure how to make sense of this. From the AST, how could I target a specific form?
The output is quite long even for that small example. Are there helper functions or will I just be calling keywords on it?
@chalcidfly do you need to execute arbitrary clojurescript expressions or are they limited to just arithmetic?
what i'm thinking is do you need to solve a quite possibly really impossible general problem or could you make an interpreter of a subset of the language
@U11BV7MTK my goal is to do arbitrary evaluation of Clojure forms
I was hoping there are methods available in cljs somewhere so that it wouldn't involve rewriting any of the interpreter
But I guess it would have to be sort of a fork of the interpreter? Just cutting the process short after a single form eval, and then converting from the AST back to a clojure form
anyone got interested to look into this function here http://repo.tiye.me/gist/investigate-fipp/ ? I found it's slow, but don't know where is the slow code
I added more details at http://clojureverse.org/t/how-to-speed-up-file-writing-from-fipp/456
@jiyinyiyong pretty printing in general is slower than normal printing, why do you need pprinted output? it doesn’t look like something a user would look at?
@jiyinyiyong There is no easy/obvious part that is causing this slow runtime. You'll likely need to get into fipp and tune it to get it faster. I'd start with: Avoiding the seq-reduce
and make it so it uses the normal (fast) reduce of the passed data structure. Not sure how easy it is, or if it's possible at all. That'd also improve on the GC problems.
I checked, but no, there is no low hanging fruit. Though, it doesn't look too difficult to make it fast in cljs.
Hi guys! How can I rewrite this function with spawn instead of exec? I tried but got ENOENT errors
(defui build-configuration [this]
[:button {:type "button"
:style {:margin-left 15}}
"Build"]
:click #(do
(when (:builder @state)
(kill-process (:builder @state)))
(let [builder (.exec child-process (str "cd " (:path @this)
(if (= (:build @this) "dev")
(str (if (= (:platform @this) "android")
" && adb reverse tcp:8081 tcp:8081 && adb reverse tcp:3449 tcp:3449"
"")
" && re-natal use-" (:platform @this) "-device " (:device @this)
" && re-natal use-figwheel && lein figwheel " (:platform @this))
" && lein prod-build")))]
(-> (.-stdout builder)
(.on "data" (fn[data]
(println data))))
(-> (.-stderr builder)
(.on "data" (fn[data]
(println data))))
(swap! state assoc :builder builder))))
Hi everybody! I'm having some trouble using clojure.pprint and cljs.pprint in a cljc file
when I use (pp/print-length-loop ...) it uses the clojure macro instead of the cljs macro
@jpmonettas 1. I'm pretty sure you don't need a reader conditional for that, clojure.pprint
will be auto aliased to cljs.pprint
@jpmonettas What evidence do you see that you are getting the Clojure macro?
To @moxaj’s 1st point, since ClojureScript 1.9.198, you can instead start writing:
(:require [clojure.pprint :as pp]))
@mfikes @moxaj the evidence is that it cant find level-exceeded var
which is a fn I think inside the clojure expanded macro
Is the code above in a namespace being required from ClojureScript as a macros namespace?
A minimal repro would help. (Perhaps the code and its usage in a gist.) @jpmonettas
yeah sure, I'm trying to move to cljs a lib I have for pprinting spec forms
I'll paste the link here
@mfikes https://github.com/jpmonettas/pretty-spec/blob/master/src/pretty_spec/core.cljc
there is only that file
@jpmonettas Here is my minimal repro attempt: https://gist.github.com/mfikes/fe449f953326d76c04e396238d2f4d34
thx for looking at it @mfikes
but for making this kind of lib, is the idea to just require clojure.pprint
or do I need the reader conditionals and the require-macros?
I tried loading your minimal repro code and it failed with
cljs.user=> (require 'pretty-spec.core)
clojure.lang.ExceptionInfo: recur argument count mismatch at line 71 /Users/mfikes/Desktop/src/pretty_spec/core.cljc {:file "/Users/mfikes/Desktop/src/pretty_spec/core.cljc", :line 71, :column 4, :tag :cljs/analysis-error}
yeah couldn't figure out why that works on clojure but not in cljs
@jpmonettas What you do in your ns
form depends on what versions of ClojureScript you want to support. (If you lib is to be used widely, and you want to support older ClojureScripts, then your approach might be better.)
got it
One thing I noticed in your code is that you refer print-length-loop
but appear to always use it qualified via the pp
alias.
yeah sorry I was in the middle of changing that when I pushed
trying to figure out how to implement that so it's compatible
Even on older versions of ClojureScript, there is no need to :require-macros
on cljs.pprint
because it requires its own macros
so if I just requiring [clojure.pprint :as pp] the compiler complains about WARNING: Use of undeclared Var cljs.core/push-thread-bindings at line 69 src/pretty_spec/core.cljc WARNING: Use of undeclared Var cljs.core/var-get at line 69 src/pretty_spec/core.cljc WARNING: Use of undeclared Var cljs.core/pop-thread-bindings at line 69 src/pretty_spec/core.cljc
I think they are on clj pprint
This is with your current repro, but changing the ns
form to be just
(ns pretty-spec.core
(:require [clojure.spec.alpha :as s]
[clojure.pprint :as pp]))
exactly
but it somehow makes sense
thats weird that's the only change I have
@jpmonettas Here is the code I tried loading: https://gist.github.com/mfikes/52272889a063bd5c974d55a4a9a255c9
I just pushed everything and this is what I'm doing to compile lein cljsbuild once Compiling ClojureScript... Compiling "target/main.js" from ["src"]... WARNING: Use of undeclared Var cljs.core/push-thread-bindings at line 69 src/pretty_spec/core.cljc WARNING: Use of undeclared Var cljs.core/var-get at line 69 src/pretty_spec/core.cljc WARNING: Use of undeclared Var cljs.core/pop-thread-bindings at line 69 src/pretty_spec/core.cljc Successfully compiled "target/main.js" in 4.9 seconds.
@jpmonettas Try reverting back down to using ClojureScript 1.9.660. I think you are seeing a bug in 1.9.671. Looking up the ticket…
yeah now it compiles
thx a lot @mfikes, I still haven't figured out the recur argument count but now it compiles ok
@jpmonettas I think I was vaguely thinking of CLJS-2069 as your problem, but it is evidently not. It also appears your problem occurs on master, so I’d suggest filing a regression JIRA.
maybe i'm reading this wrong. https://dev.clojure.org/jira/browse/CLJS-1800 says fix version is 1.9.671
but that version was released 21 days ago and the actual patch that fixed it was applied 13 days ago. doesn't compute.
@jiyinyiyong the demo with profiling is helpful. thank you. it looks like the bounded-count routine is a little slow on cljs, i will look at it more closely
i made a performance/design mistake that i’m stuck with in vim to treat text and pass nodes as variadic
@bbloom apply
should be much faster in 1.9.671, which version are you trying?
Oh hrm, no console on mobile
I'll take a look later
Perhaps there's a _STAR_clojurescript_version_STAR_
in there
@anmonteiro Already checked, got compiled out
The bounded count is part of apply
. And it's used b/c of the lazy seq's. Can you do the transformations non-lazy @bbloom ?
yeah, was jus tlooking for it 🙂 when @jiyinyiyong returns, maybe he can let us know & try 1.9.671 or newer
I think doing non-lazy transformations in Fipp would result in it not being memory-bound anymore
@rauh not really - the only way to go non-lazy would be to use concurrency primitives, which would be even slower
My apply optimizations don't kick in when calling variadic fn's. So there is no gain with the new version.
the serialize function produces a command sequence, but it relies on laziness to prevent realizing the full document in memory
I do have more apply optimizations in the pipeline that also speed up this exact case, but it's not ready yet.
@rauh thank you. please elaborate. what’s “this exact case”, why is it slow, and how are you going to improve it?
@bbloom I sped up apply for calling non-variadic fns (incl. mutli arity) but you seem to be calling mostly variadic fn's with apply
, which is still kinda slow (not that slow actually).
@bbloom The bounded count was always in the apply
fn. That didn't change. But I do want to change it in the future to avoid it completely.
hm ok - i don’t really use fipp from cljs much, so i didn’t profile it extensively myself
i’m only looking at it now on behalf of @jiyinyiyong
@rauh i’m working off memory here, but isn’t repeat a efficient reducable? that shouldn’t allocate a seq at all, right?
(defn repeat
"Returns a lazy (infinite!, or length n if supplied) sequence of xs."
([x] (lazy-seq (cons x (repeat x))))
([n x] (take n (repeat x))))
fipp’s engine is cljc, there has never been platform specific code in it - i don’t want to start now if i can help it
ok, still not even sure it really matters, since that’s far from the bottleneck vs the serialization routines, which are much more allocation and apply heavy according to profiles
also, i’m not even sure this is an issue, as fipp is still quite fast for iteractive use
@jiyinyiyong does some crazy stuff with a crazy custom projectional non-text editor he wrote and pretty prints things, so his needs are bigger
i had a little spare time between meetings this morning, so i figured i’d look at this - if ppl who actively work on the cljs compiler/runtime need a good test case for improving the seq/bounded-count/apply codepath, i’m happy to help via insights in to fipp
@bbloom fipp is great, just discovered it and I'm moving all my clojure.pprint code to fipp documents
how do you dispatch on sequences in multimethods given that (isa? cljs.core/List cljs.core/ISeq) => false ?
guessing it must be part of a namespace, so i could create a simple namespace then add them all to an externs file. is that it, or is there an easier way?
(defn ^:export myfn ...
?
@devth it’s literally just a call to goog.exportSymbol
https://google.github.io/closure-library/api/goog.html#exportSymbol
@anmonteiro awesome. thx!