This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-30
Channels
- # admin-announcements (42)
- # alda (8)
- # aws (10)
- # beginners (22)
- # boot (165)
- # bristol-clojurians (1)
- # cider (6)
- # clara (21)
- # cljs-dev (23)
- # clojure (74)
- # clojure-dev (8)
- # clojure-russia (41)
- # clojurescript (180)
- # core-async (11)
- # cursive (26)
- # datascript (2)
- # datavis (7)
- # datomic (29)
- # editors (1)
- # hoplon (7)
- # jobs (3)
- # ldnclj (4)
- # lein-figwheel (47)
- # leiningen (2)
- # mount (26)
- # off-topic (3)
- # om (163)
- # onyx (56)
- # proton (4)
- # reagent (6)
- # remote-jobs (1)
- # ring-swagger (4)
- # spacemacs (9)
hey grav
did a little googlin
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of
for...of is equivalent to obj.forEach
which you can access in cljs with the interop syntax
Look at https://github.com/crocket/convert_to_utf8/blob/4b3bd959d4e45e53ce21d7dd90e06bda5cfe1bb6/src/cljs/convert_to_utf8/core.cljs#L69-L78 if you want to know how transducers can be modified to process a single map rather than a collection.
Is there a way to use npm modules on advanced optimization mode without :externs? I run my clojurescript program on nodejs.
thanks @donmullen
@crocket: no but there’s really few compelling reasons to use any Closure optimization setting at all under Node.js
@crocket: I’ve seen scant evidence that using optimizations on ClojureScript code bases having a worthwhile gain on startup time at all especially under modern JS engine like V8
so in my opinion you’re just creating unnecessary complication for little benefit - happy to see numbers that prove the effort is worth the trouble
I guess :simple optimization is a sane tradeoff for production build, then. It doesn't break external modules.
Would the effort on :advanced optimization be worth the trouble on web browsers for now?
@crocket I don’t follow - Closure advanced optimizations is specifically to address web clients
@crocket: FWIW for minimizing startup latency in non-web applications, I tried :simple
in Planck and :none
actually ended up being slightly faster.
With :simple, there is just one javascript file. With :none, I get plain javascript files incompatible with nodejs.
Somehow, I had to specify :main
in :compiler
to make my clojurescript program work with no optimization.
On my machine, a clojurescript nodejs program boots up in 0.2 second on :simple
optimization. It boots up in 0.4 second on :none
optimization.
Is there an existing function that substitutes (defn clj-fn->js [fn] #(clj->js (apply fn %&)))
?
@loganlinn: thanks
you’re aware of *main-cli-fn*
, yeah? https://github.com/clojure/clojurescript/wiki/Quick-Start#running-clojurescript-on-nodejs
https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/nodejscli.cljs may be interesting to check out
> How can I target a nodejs build with optimization :none?
> With :simple, there is just one javascript file. With :none, I get plain javascript files incompatible with nodejs.
Not sure your use case, but :modules
compiler option maybe useful
https://github.com/clojure/clojurescript/wiki/Compiler-Options#modules
@loganlinn: How do you create npm modules with clojurescript? *main-cli-fn*
seems to prevent me from creating an npm module.
It seems I have to use the following code.
;;
(defn invoked-directly?
"If it's required, false. If it's invoked by node.js, true"
[] (identical? (.-main nodejs/require) js/module))
(defn -main []
(if (invoked-directly?)
(-main-cli)
(set! (.-exports js/module) #js {:clean_buffer (comp clj->js clean_buffer)
:clean_file (comp clj->js clean_file)
:clean_file_and_save
(comp clj->js clean_file_and_save!)})))
(set! *main-cli-fn* -main)
Does anyone know can you change the print-length variable?
*print-length*
also how do you type earmuffs in markdown XD
Thanks
I guess it was an issue with CIDER, set! just hanged forever, I updated it to 0.11.0-SNAPSHOT and it works now.
@drakezhard: Do you want http://clojure.github.io/clojure/branch-master/clojure.core-api.html#clojure.core/binding ?
I'm sure it was CIDER because (range 0 10 0.001) hung for ever too before the update.
The error was No response handler with id 4 found, I guess that nrepl was sending the js to dev/null
How would you make an npm library that includes an executable with clojurescript? It's hard to write idiomatic code when I want to build index.js
and bin/executable.js
from cljsbuild and utilize index.js
from bin/executable.js
. Doing it seems to require using nodejs/require
, and it feels weird to import index.js
from bin/executable.js
with nodejs/require
.
I'm getting java.io.FileNotFoundException: The file out/no/en/core.cljc does not exist.
when running tests with lein-doo. Does it mean that compilation was unsuccessful (stack trace is not very helpful in this case)?
@jindrichm: Did you check the file actually? By the way, I don't know any better than you.
@crocket: Yes. I've found that lein-doo actually compiles JS into /out instead of /resources/public/js/out.
.cljc is a file extension of a source code. It shouldn't be in the build folder. Or, does it compile .js into .cljc?
It seems that lein clean
does not clean all artifacts from previous compilations. Cleaning them manually fixes this issue for me.
However, I still don't get why lein-doo compiles into /out
, while lein-figwheel compiles into /resources/public/js/out
.
@jindrichm: A good way to figure out is to read their code.
Now I see it's the :output-dir
compiler setting that defaults to the project root. Thanks for the hints, @crocket!
@jindrichm: you need to supply :clean-targets
to lein, refer to lein documentation about that
far as doo defaults, I would refer to the docs and if they are not forthcoming - ping bensu when he is around
Yes, I used :clean-targets
already. The problem was that I was unaware that CLJS build without an :output-dir
defaults to the /out
.
I think this is not specific to lein-doo.
@crocket: there is very little support to create ClojureScript NPM modules, very few people do this as a result. Most people targeting Node.js are just building applications or just taking advantage of the convenient REPL. If you go down this route you’ll be on your own.
@jindrichm: yes out
is the default output directory if nothing else is supplied
@dnolen: I'm creating a lein template for clojurescript npm modules. It is possible, but it is going to need some template for convenience.
@crocket: as I said not a highly recommended path unless you’re interested in a very long haul due to my above comments
a few people have investigated this before and it’s a lot more work to make something that people would actually want to use than it may first appear.
I'm slowly realizing that writing an npm executable in clojurescript is not worth the effort individually.
At this time I would agree. Would require patches and discussion on both Closure Compiler and ClojureScript compiler dev channels if you want something useable.
GSoC covered some initial work but Node.js is more complicated than CommonJS - because it isn’t actually CommonJS
I implemented a hack below.
:cljsbuild {
:builds [{:id "dev"
:source-paths ["src/cljs" "src/bin"]
:figwheel true
:compiler {
:main to-utf8-unix.core
:output-to "target/server_dev/to_utf8_unix.js"
:output-dir "target/server_dev"
:target :nodejs
:optimizations :none
:source-map true}}
{:id "lib"
:source-paths ["src/cljs"]
:compiler {:main to-utf8-unix.core
:output-to "index.js"
:output-dir "target/server_lib"
:target :nodejs
:optimizations :simple}}
{:id "bin"
:source-paths ["src/bin"]
:compiler {:main executable.core
:output-to "bin/to-utf8-unix.js"
:output-dir "target/server_bin"
:target :nodejs
:optimizations :simple}}]}
The figwheel REPL has access to both library and executable. If it becomes any more complex, I'll have to consider boot.
@crocket: I have no idea, I do not intend to work on it myself nor am I aware of anyone else that intends to. It’s also a lot of work for incredibly marginal benefit today - most users are not using Node.js on the backend.
Node.js has always been a testing path, REPL thing - few users seem to care about it for anything else.
If clojure on JVM was fast to launch, I wouldn't have had to walk on this path. I'm looking for a way to use a decent functional langauge for shell scripts. Is there an already established alternative?
Clojure is fine for non-trivial shell scripts, 0.5-0.7 seconds on modern hardware just makes this less and less interesting every day.
that said the primary use case for Clojure and ClojureScript isn’t shell scripts so again a vast lack of interest
I packaged an uberjar via leiningen, and it took 3-4 seconds to make it print anything. Do you know any decent functional language for shell scripts?
I was experimenting with clojure as a potential language for shell scripts in the past.
At this point, I am considering OCaml, Haskell, Racket, and other scheme dialects for shell scripts.
What are the scenarios where you need figwheel into the executable and fast startup?
I'd have thought that if the startup was fast, you'd iterate by running the script again
I forgot, but there is some kind of server where you could send your clojure code and it will run it fast
also, I just have to recommend my ruby shell :) https://github.com/s-mage/rush
Ok, I don't want to write a shell script but a small command line program. Bash is ok for composing command line programs.
This conversation is now becoming less relevant for this channel :) let's stay focused on ClojureScript or take it elsewhere.
I just realized that requiring a library namespace from an executable namespace is way better than importing the library as a nodejs module.
yeah, build up a lib mostly in the repl and then when you’re done expose that lib via a main function
I created a new npm module written in clojurescript. https://github.com/crocket/to-utf8-unix
hey @jindrichm, in case you didn't find your answer. So far, doo has no "defaults" it passes the compilation options directly to the compiler. The compiler has out
as default :output-dir
which is not included in lein's :clean-targets
. It is not a good idea to target the test build and dev build to the same dir.
@bensu: Thanks for clarification. I have eventually figured out, that my problem was indeed a generic compiler thing, rather than something specific to lein-doo.
If multiple namespaces have *main-cli-fn*
set to their own -main
and :main
is set to one of those namespaces, what happens to *main-cli-fn*
in every other namespace?
@crocket: if you set dynamic vars multiple times in multiple namespaces that will just clobber the bindings if they are a part of the same build
if doesn’t have to do with the ClojureScript, core.logic, or core.match don’t assume I have anything to do with it
I have worked on core.async on the past as a contributor but I was never involved in the nitty gritty compilation bits
but it will likely just sit around until somebody in the community starts working on it again
Couldn’t find anything in the Google Closure library that works with JS iterators (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator), so I created a simple function that does:
(defn js-iterator-to-vec
[it]
(loop [a []]
(if-let [v (-> (.next it)
(.-value))]
(recur (conj a v))
a)))
@johannjohann Problem with these things are that they can only be handled with for .. of
(not always forEach
), or by repeatedly calling .next()
@dnolen: Darn! I’ve googled "js iterator clojurescript" a million times without any luck!
at the risk of re-opening the not-terribly-productive discussion from the other night - is there a general rule for stuff like that about whether it’ll be added to cljs.core or some other namespace?
i was in the middle of implementing itr->seq
when i saw the reference to es6-iterator-seq
I published a post of how to interop with ClojureScript from vanillaJS and React. http://bit.ly/fluxless
And an entry into ClojureScript and how we built a full data layer for the Capital One web app. http://bit.ly/triforce-of-power
There is a typo in your first code example, @puppybits
@glenjamin: the normal answer to whether something will be added to core is usually “no"
further ES6 enhancements should be discussed in #C07UQ678E or the ClojureScript mailing list
I was thinking they could go in cljs.es6 or similar - much like the nodejs and browser namespaces - would bring core into more parity. Probably not worth moving stuff that's already in though
@glenjamin: we’re not going to make an es6 namespace
the browser ns is effectively deprecated and nodejs namespace is just 2 or three helpers - so they aren’t really precedents anyhow.
I was thinking more about the other direction - how many vars are in cljs but not clojure.
I see, host stuff you'd expect to stay at the edges of a program - and not affect portability heavily