This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-06-10
Channels
- # aleph (4)
- # announcements (27)
- # aws (12)
- # aws-lambda (1)
- # beginners (207)
- # boot (4)
- # calva (8)
- # cider (9)
- # clj-kondo (9)
- # cljs-dev (27)
- # cljsrn (6)
- # clojure (104)
- # clojure-android (3)
- # clojure-dev (9)
- # clojure-finland (2)
- # clojure-italy (18)
- # clojure-spec (8)
- # clojure-uk (100)
- # clojurescript (43)
- # clojutre (1)
- # core-async (49)
- # cursive (18)
- # data-science (3)
- # duct (24)
- # events (2)
- # fulcro (27)
- # immutant (1)
- # off-topic (32)
- # om (2)
- # onyx (2)
- # pathom (14)
- # pedestal (2)
- # planck (3)
- # re-frame (38)
- # reagent (7)
- # reitit (10)
- # rewrite-clj (7)
- # ring-swagger (3)
- # shadow-cljs (32)
- # spacemacs (63)
- # test-check (16)
- # tools-deps (5)
- # vim (21)
Top-level requires are only for REPL/scripts and not for compiled targets, is that correct?
but we spent some time to make sure it would work for compilation in general - so if something is amiss file a ticket
I tried loading cljs files using (load-file) once is a self hosted target and it is impossible as there is no way to do this properly as it seems the files depend on some analyzer data.
load-file
probably isn't the right way to load files, self-hosted or otherwise. But maybe I'm misunderstanding what you mean.
Let me explain what i was trying to do, i was trying to create a scriptable browser in cljs+electron, the idea was to have a self hosted cljs in the browser as well as the electron runtime that starts the main window. So that user configurable scripts can be put into say a home directory ~/.mybrowser/init.cljs somewhat like emacs. Now i used load-file because this path is not a part on the src/ load path of the rest of the program. But still it turned out to be difficult because even if somehow i got the string content of the file the context in which self hosted cljs runs is different from the main application it may not have access to many of the libs of the main program. èval-str`isnt equivalent to js èval` it seems to be not running in the same context or doesnt have access to any other namespace.
@dnolen the documentation only speaks about REPL. Would you advice against separate requires if you can avoid them, e.g for mark them as ‘side effecting’ for tooling? We’re trying to come up with some kind of way to signal that to tooling and some people have been doing it like this in JVM Clojure
@metacritical ok, but far as I can tell all those problems are solveable w/ the current set of tools in cljs.js
- the caveat being that is pretty advanced stuff
@metacritical walking through all of it isn't practical wrt. time to explain - you might want to look at existing efforts - lumo, planck, etc.
@dnolen Will try and have a look thanks!
I believe borkdude is working on a linter, and he wants to warn users when a namespace has been required (through the ns
form usually), but hasn’t been used.
however, some namespaces are required only for their side effects on load. so he is trying to figure out a way to let users hint at the linter (and other tooling that might be built) that a require is done only for side effects
I believe near the bottom of the above issue, someone suggests using top-level (require ...)
for side-effects instead of the (ns ... (:require ...))
and there were some questions about it’s usability outside of the REPL
I’m back now. @lilactown is correct. so per the suggested style you would have something like:
(ns foo (:require [clojure.set :as set]))
(require '[cljsjs.foobar]) ;; only used for foreign lib loading
(set/union #{} #{})
so tooling would not remove cljsjs.foobar
even though it’s not explicitly used in the code of the namespaceI was wondering if this would always work, as the docs hint that require
in CLJS is used for the REPL
@borkdude I don't think this landed in any formal documentation but ns
followed by require
is not consistent with this post https://anmonteiro.com/2016/10/clojurescript-require-outside-ns/
@mfikes in his foo.cljs
file, what would be the namespace name - there doesn’t seem to be an ns
form
also, I’m not asking anyone to implement this, just want to know if it’s supposed to work, or brittle in any way and therefore it may not be recommended
right, because there is no ns
form yet. in the REPL, when you do this, the namespace name is set by the previous (ns ...)
expression
I tried this out:
;; src/nstest/core.cljs:
(ns nstest.core)
(require '[clojure.set :as set])
(defn foo [] (set/union #{} #{}))
(defn -main [& args]
(println (foo)))
(set! *main-cli-fn* -main)
;; compile with:
;; clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.520"}}}' -m cljs.main -re node -c nstest.core
Result:
node out/main.js
goog.require could not find: nstest.core
That seems enough evidence that it isn’t supported@borkdude I thought that worked? But that wasn't the real thrust of what we were supporting since it's not meaningful to do it that way
hey @thheller I just saw you provided guidance on clojureverse for implementing webcomponents in cljs. Just wanted to say THANK YOU! I've been looking for that info for a while and it all sort of came together with your reply about the super constructor this morning! for anyone interested in webcomponents, bookmark this thread for later: https://clojureverse.org/t/how-to-create-custom-elements-web-components-with-clojurescript/4332/5
I've been doing clojure for a while, but I'm a newbie at clojurescript. Is it possible to build libraries, callable from javascript, specifically node.js, using clojurescript? I've found lots of references to calling javascript from clojurescript, but not the other way around. I found this: https://lambdaisland.com/blog/2017-05-02-nodejs-scripts-clojurescript, but I don't want to build an executable script - I want to build a library. So, any pointers, suggestions, comments as to why this is a bad idea, etc. are welcome.
Haven't looked at how it works, but I know datascript does this: https://github.com/tonsky/datascript#using-from-vanilla-js
Interesting - I'll give their build a look. I'm building a query language implementation, too. The system is implemented as a parser service, written in antlr, node, and express, which produces a simplified parse tree to pass to the interpreter service (it makes more sense than it sounds like, given the language) which will be written in clojure. The front end of the whole thing (which at this point isn't much more than an input and output window linked by the parser service) is being written in clojurescript and reagent. The reason I want build a clojure library is that I'd like to do constant-folding in the parser service, and to get similar semantics, I'd like to use the same code in the evaluators on both sides of the fence. Since some of the semantics of the primitives in the evaluator are complex, dealing with imprecise timing relations, I'd prefer to write it in .cljx.
it might be worth looking at cljc its whats support better nowadays https://clojure.org/guides/reader_conditionals