Fork me on GitHub
#clojurescript
<
2019-06-10
>
borkdude12:06:25

Top-level requires are only for REPL/scripts and not for compiled targets, is that correct?

dnolen13:06:52

not really

dnolen13:06:18

though that was the main driver for making it work

dnolen13:06:39

but we spent some time to make sure it would work for compilation in general - so if something is amiss file a ticket

dnolen13:06:03

things to be aware of

dnolen13:06:13

any file w/o an ns is cljs.user

dnolen13:06:21

var clashes are possible

dnolen13:06:00

(and expected really)

metacritical13:06:01

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.

dnolen13:06:16

load-file probably isn't the right way to load files, self-hosted or otherwise. But maybe I'm misunderstanding what you mean.

metacritical13:06:28

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.

borkdude14:06:12

@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

borkdude14:06:36

E.g clean-ns would leave such requires alone

dnolen14:06:13

@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

4
dnolen14:06:53

@borkdude I'm just not following?

dnolen14:06:07

even in Clojure user.clj is general a dev time thing

dnolen14:06:16

so what problem are you actually trying to solve here?

borkdude14:06:48

I’ll reply when I’m not on mobile

dnolen14:06:03

@metacritical walking through all of it isn't practical wrt. time to explain - you might want to look at existing efforts - lumo, planck, etc.

metacritical14:06:04

@dnolen Will try and have a look thanks!

lilactown15:06:22

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

lilactown15:06:37

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

borkdude15:06:08

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 namespace

borkdude15:06:30

I was wondering if this would always work, as the docs hint that require in CLJS is used for the REPL

borkdude15:06:43

^ @dnolen hope it’s clearer now

mfikes15:06:07

@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/

borkdude15:06:00

@mfikes in his foo.cljs file, what would be the namespace name - there doesn’t seem to be an ns form

borkdude15:06:25

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

mfikes15:06:46

In his foo.cljs file, the namespace would be cljs.user

borkdude15:06:31

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

mfikes15:06:28

(This is just from rule 6 in António's post)

borkdude15:06:35

per his post it’s or/or/or

borkdude15:06:34

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

borkdude15:06:41

thank for the link to Antonio’s blog @mfikes, very helpful

dnolen16:06:27

@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

borkdude16:06:53

I tried it and it seems it didn’t, unless I did something wrong.

idiomancy20:06:51

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

fadrian22:06:19

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.

codonnell22:06:37

Haven't looked at how it works, but I know datascript does this: https://github.com/tonsky/datascript#using-from-vanilla-js

fadrian23:06:18

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.

tavistock23:06:36

it might be worth looking at cljc its whats support better nowadays https://clojure.org/guides/reader_conditionals