clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
suren 2021-01-13T01:01:53.292600Z

Is it possible to use local library in Clojurescript like we can do in Clojure? Will deps like below work?

{:deps
 {time-lib/time-lib {:local/root "../time-lib"}}}

suren 2021-01-13T01:02:56.293600Z

From personal experience it does not seem to work. Just wanted to make sure its doable.

dpsutton 2021-01-13T01:26:13.294300Z

it should. because everything works on a classpath. should be no difference if its in a jar in ~/.m2/repository/... or ../time-lib

suren 2021-01-13T01:42:39.299500Z

Got it working, the directory structure at the local library did not match the namespace. Thanks @dpsutton

dpsutton 2021-01-13T01:43:35.300300Z

glad to hear. simple tools mean that the bugs can't hide too much

👍 1
p-himik 2021-01-13T10:57:44.305500Z

As a person working with scientific data, I find that page absolutely meaningless and just very unpleasant to look at. Good only, perhaps, for a chitchat over some beers.

☝️ 1
vnctaing 2021-01-13T02:46:13.301100Z

It seems like interest for clojurescript from the JS community is still dropping years after years

raspasov 2021-01-13T04:41:05.301500Z

@vnctaing I don’t want to make excuses but such a comparison does not seem very fair; I have never used TypeScript but it seems to me that it is effectively a … superset of JavaScript? Basically you just need to learn a few things, and you can get going on top of JavaScript; sort of like what spec is to ClojureScript… ClojureScript is a whole new way of thinking compared to JavaScript

2021-01-13T05:18:43.301900Z

I always found this survey kind of weird in its results. I'm not sure who answers it, but I'm always kind of surprised by the data, like its almost... odd

seancorfield 2021-01-13T05:18:44.302100Z

Just saw this thread in the archive on Zulip and I went and looked at that infographic and it's really misleading because it isn't to scale. Usage has remained steady (3%), awareness has hardly changed, Interest dipped by 12% but Elm is down nearly 30% (and it looks like Reason is up but it's actually 11% down from when it was first noted). Satisfaction has dropped 8% but the graph makes it look like it has tanked... And Elm's usage and awareness are both actually up but satisfaction and interest seem to have tanked -- how can that be?

😮 1
2021-01-13T05:23:57.302300Z

I knew something was up with it 😛

seancorfield 2021-01-13T05:24:32.302500Z

It's like a subway map 🙂

3
2021-01-13T05:29:51.302800Z

On the topic of satisfaction though, I can see a lot of JS devs not liking ClojureScript, its so different, so much to learn, and if you just find yourself having to work on some ClojureScript code base, and you're a front-end dev with a JS background, I can see being a little frustrated by this.

2021-01-13T05:32:13.303Z

Especially mixed with the front-end world. Last time I did front-end, you're not really programming, you're configuring a framework to do what you want, and the most frustrating thing is not finding the documentation that tells you the knob that you need for the the thing to do what you want. Which I can imagine Cljs must have the least amount of resource for that.

2021-01-13T05:33:52.303200Z

If you don't know Clojure enough to quickly peek to the implementation of reagent, rum, etc. And see the intersection with React, to be able to map in your head the React documentation to what you're doing, I can imagine that being really painful.

2021-01-13T05:37:47.303400Z

Which is why I feel, with "satisfaction" survey, I wish it would have something that tells me: of those that are satisfied, just how much are they? Cause its telling if something has overall low satisfaction, but of those that are satisfied, they are all fully satisfied and just in absolute joy with it. Versus something that has a lot of people being satisfied, but no one is like really in love with it.

borkdude 2021-01-13T11:37:49.306100Z

How do I get rid of this error message in self-hosted CLJS?

ClojureScript 1.10.597
cljs.user=> (defmacro ctx-fn [ctx-bind & body]
       #_=>   `(with-meta (fn [~ctx-bind]
       #_=>                 ~@body)
       #_=>      {:sci.impl/op utils/evaluate}))
#'cljs.user/ctx-fn
cljs.user=> (ctx-fn ctx nil)
                    ^
WARNING: Use of undeclared Var cljs.user/ctx at line 1

borkdude 2021-01-13T11:39:18.306300Z

cljs.user=> (defmacro foo [x] `(fn [~x]))
#'cljs.user/foo
cljs.user=> (foo x)
                 ^
WARNING: Use of undeclared Var cljs.user/x at line 1
(cljs.core/fn [nil])

borkdude 2021-01-13T11:39:20.306500Z

:thinking_face:

thheller 2021-01-13T11:40:24.307300Z

can't define macros in CLJS like that. not sure about self hosted but the way above will just call it like a function

borkdude 2021-01-13T11:40:44.307900Z

right

borkdude 2021-01-13T11:41:06.308400Z

I did put a #?(:cljs (:require-macros [sci.impl.analyzer :refer [ctx-fn]])) in my ns decl

thheller 2021-01-13T11:41:09.308600Z

not actually sure you can do this in the REPL

borkdude 2021-01-13T11:41:41.309100Z

don't care about the REPL, I just wanted to get rid of the > WARNING: Use of undeclared Var cljs.user/ctx at line 1 warning in my code for self-hosted during load time

thheller 2021-01-13T11:44:28.310200Z

it looks to me like the macro is being called as a function rather than a macro but thats where my self-host knowledge ends 😉

borkdude 2021-01-13T11:45:09.310600Z

yet it does work in self-hosted when called

borkdude 2021-01-13T11:45:52.311Z

I used macrovich to solve similar issues, but this time around it doesn't seem to work

borkdude 2021-01-13T11:52:28.311700Z

ah well, I got rid of the macro. less macros, less problems

😎 1
Sam Ritchie 2021-01-13T19:11:37.313800Z

Found a subtlety of CLJS this AM that I wanted to run by y’all - == calls out to -equiv, but it doesn’t seem to pick up on any NEW -equiv implementations. maybe it is bound at compile time? The var #'== on the other hand does do the right thing when applied. for example:

(deftype Wrapper [x]
  IEquiv
  (-equiv [_ that]
    (-equiv x that)))

(let [x (Wrapper. 10)]
  (== x 10)     ;;=> false
  (#'== x 10))  ;;=> true

thheller 2021-01-13T19:16:23.314500Z

@sritchie09 my guess would be that because of the 10 number a compiler optimization kicks in to use JS ===. guess that doesn't account for custom -equiv impls comparing to numbers

Sam Ritchie 2021-01-13T19:17:09.314900Z

yup, exactly, which is what I was installing

Sam Ritchie 2021-01-13T19:17:30.315600Z

Ratio support, js/BigInt for two clearcut cases

Sam Ritchie 2021-01-13T19:18:00.316300Z

and for a slightly funkier one, an automatic differentiation implementation that needs to compare “dual numbers” to normal numbers using just the primal-part, not the tangent-part

Sam Ritchie 2021-01-13T19:19:43.316800Z

@thheller actually, if I throw a println in the -equiv impl and call (== x x) it looks like my custom -equiv never gets called, even if no number is passed as an arg

thheller 2021-01-13T19:20:50.317300Z

well = is equiv

thheller 2021-01-13T19:21:01.317600Z

isnt' == just a numerics things?

Sam Ritchie 2021-01-13T19:21:21.317900Z

(defn ^boolean ==
  "Returns non-nil if nums all have the equivalent
  value, otherwise false. Behavior on non nums is
  undefined."
  ([x] true)
  ([x y] (-equiv x y))
  ([x y & more]
   (if (== x y)
     (if (next more)
       (recur y (first more) (next more))
       (== y (first more)))
     false)))

Sam Ritchie 2021-01-13T19:21:26.318100Z

not according to its implementation

alexmiller 2021-01-13T19:21:43.318800Z

Behavior on non nums is undefined.
?

Sam Ritchie 2021-01-13T19:21:50.319200Z

oh 🙂

thheller 2021-01-13T19:21:54.319500Z

its probably a function with a macro inlining stuff

thheller 2021-01-13T19:22:07.319900Z

(core/defmacro ^::ana/numeric ==
  ([x] true)
  ([x y] (bool-expr (core/list 'js* "(~{} === ~{})" x y)))
  ([x y & more] `(and (== ~x ~y) (== ~y ~@more))))

thheller 2021-01-13T19:22:20.320200Z

as expected uses JS === directly

Sam Ritchie 2021-01-13T19:22:41.320600Z

okay, got it

Sam Ritchie 2021-01-13T19:22:55.320800Z

thanks for the help sleuthing!

Sam Ritchie 2021-01-13T19:23:50.321400Z

another spot that seemed like it might beg a patch was compare, which has this branch for numbers:

Sam Ritchie 2021-01-13T19:23:50.321600Z

(number? x) (if (number? y)
                 (garray/defaultCompare x y)
                 (throw (js/Error. (str "Cannot compare " x " to " y))))

Sam Ritchie 2021-01-13T19:24:31.322400Z

garray/defaultCompare works great between numbers and goog.math.Long or goog.math.Integer , but we can’t get there with this branch

Sam Ritchie 2021-01-13T19:25:24.323Z

int? and pos-int? check for these types, so perhaps the right side should check for them here too?

Sam Ritchie 2021-01-13T19:27:02.324700Z

(unfortunately I still had to make a new compare implementation in sicmutils, because with the special case for number? there is no way to get a number to compare to a js/BigInt instance. These also work well with garray/defaultCompare, but we don’t speak js/BigInt anywhere else so I wouldn’t expect that to come in. If the number? case were removed and fell through to a new -equiv implementation for numbers, however, then I could override that.

thheller 2021-01-13T19:52:38.325200Z

might be worth taking this to http://ask.clojure.org or direct jia issue. stuff tends to get lost in slack.

👍 1
Helins 2021-01-13T21:25:35.326800Z

I didn't find anything about that so I don't think so, but is it possible to obtain a list of original names -> munged names after advanced compilation?

danieroux 2021-01-14T09:29:31.001500Z

Depending on what you need this for, I use https://clojurescript.org/reference/compiler-options#pseudo-names to debug advanced compilation issues.

Helins 2021-01-15T10:28:57.007200Z

Indeed, I forgot about source maps! That might be exactly what I need.

nnichols 2021-01-13T21:36:16.326900Z

I’m not sure about recovering the mapping, but if you need a reliable name post-munging you can add ^:export

phronmophobic 2021-01-13T21:38:30.327100Z

depending on what info you need, check out the source map files that clojurescript can produce

phronmophobic 2021-01-13T21:38:47.327300Z

https://clojurescript.org/reference/source-maps

phronmophobic 2021-01-13T21:39:50.327500Z

and https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/ for interpreting the source maps