Fork me on GitHub
#clojurescript
<
2022-04-17
>
rayat16:04:30

Hello! How do I do the equivalent of an instanceof predicate for spec?

p-himik16:04:59

No such thing exists in the spec itself. You can trivially do it yourself via a plain predicate, #(instance? MyClass %).

rayat16:04:38

Ah ok makes sense, just saw that in the cheatsheet as well. Thanks @U2FRKM4TW!

👍 1
pinkfrog16:04:21

cljs does not have alter-var-root. How can I write a function that takes in a var and alters it?

p-himik16:04:30

You can't.

lilactown18:04:07

vars are not reified in cljs

pinkfrog00:04:54

> vars are not reified in cljs reified means instantisated to me. vars are not instantiated sounds a little mysterious.

pinkfrog11:04:35

> You can’t. Worst case I can rerun (def some-var val) provided I can reflect to get the name some-var from the passed in var.

thheller11:04:03

what are you trying to do? vars don't exist in cljs like they do in clj. so whatever you do manipulating them will have some limitations

thheller11:04:48

so in CLJ clojure.lang.Var is an actual thing you can use at runtime. in cljs it is not.

pinkfrog14:04:05

Sounds like the var object exists

(comment
  (def *a 1)
  ;; cljs.core/Var
  (println (type #'*a))
  ;; -413467973
  (println (hash #'*a)))

p-himik14:04:31

Right, and apart from the above, deref and invoking are pretty much the only things you can get from CLJS vars. You can't alter them. Given your other questions about exposing a namespaces via another one, seems like you're trying to do something strange which might easily be a case of the XY kind of problem. So, can you describe what your X is, what are you actually trying to do?

thheller16:04:48

yes, the var macro exists. but its a macro, so you can't use it dynamically

thheller16:04:08

also the results are always different so (identical? #'a #'a) works in clojure but doesn't in CLJS

lilactown18:04:29

anyone have a quick trick for loading NPM modules in a plain CLJS browser REPL?

lilactown18:04:52

or am I stuck with either :target :bundle or using shadow-cljs?

lilactown18:04:14

(I would use shadow-cljs but Calva doesn't have great support for browser REPL yet)

rayat21:04:11

Interested to know: • What you're working on • What Calva isn't doing • You typically use emacs, curious about your exploration of Calva here

lilactown00:04:28

decided to try and learn to use Calva. spending a few hours on a simple side project that I don't want to configure a build for 😛

❤️ 1
lilactown00:04:55

I put the issue I was having with using shadow-cljs browser REPL in the issue you responded to https://github.com/BetterThanTomorrow/calva/issues/1683

rayat01:04:42

> pssst might be worth reposting in #calva maybe