Fork me on GitHub
#clojurescript
<
2022-09-20
>
kenny18:09:24

Hi. Given a symbol, can I resolve it to its value? e.g., in Clojure at runtime you can @(resolve 'foo/bar). This is not possible at runtime in cljs, correct? Is it possible at compile time?

p-himik18:09:15

Correct. And at compile time you can use a macro. Of course, that foo/bar must then be available during compilation in .clj or .cljc.

1
kenny18:09:27

& I'd do the resolution just like I would in Clojure with the resolve function?

thheller18:09:13

not resolve no. what do you intend to do? there is cljs.analyzer.api/resolve

thheller18:09:33

but var based programming is severly limited due not CLJS not actually having reified vars in the runtime

thheller18:09:55

so anything you try to do is probably limited

p-himik18:09:47

If you do resolve within a macro and you would like to resolve a CLJ var and not a CLJS var, then yes, it would be a regular resolve.

kenny18:09:10

My objective is to determine that the spec ::enum in the below form is pointing to a symbol that resolves to a set literal. e.g., I call (s/form ::enum) which yields user/enum-set. I now would like to determine if that symbol is a set literal or not.

(def enum-set #{:a :b})

(s/def ::enum enum-set)

thheller19:09:27

not possible

kenny21:09:36

Even in macro land?

Lone Ranger21:09:24

@U083D6HK9 kind of a pain but I've moved to using implements? and protocols to accomplish similar tasks. was an enormous overhaul.

kenny00:09:35

Not sure I'm following. How is that an alternative?

thheller05:09:21

the issue is that the cljs.analyzer/compiler never actually evaluate any of the JS code they generate. so accessing things that are only "created" at runtime doesn't work. so in theory you can get the actual source string of the def, but it'll be limited. what you really need to know is the value of the def, but that doesn't exist during compilation/macro expansion.

Lone Ranger10:09:54

@U083D6HK9 I probably misread what you were saying as a broader discussion on strategies for data validation in clojurescript, so probably not on topic

Steph Crown19:09:08

Hi guys. How can I connect my ClojureScript project to Calva. I've tried using CTRL + ALT + C, but it doesn't work in .cljsfiles. it only works in .clj files.

pez19:09:45

Is the project REPL running, or have you tried with letting Calva start it? This is the main doc page about connecting a project: https://calva.io/connect/

Steph Crown20:09:38

Yes the project's REPL is running on localhost:9500

Steph Crown20:09:58

I have tried to Let Calva start the server, and it successfully started it, but I was not able to evaluate expressions in my IDE using ALT + ENTER.

pez20:09:26

Port 9500 indicates that it is a Figwheel project, is that correct?

pez20:09:10

And if so, that is not the REPL port, it is the web server port serving the application.

pez20:09:15

Hmmm. Can you describe the steps you take when you try to connect the REPL? I do think that letting Calva start the REPL and Connect (aka Jack-in) is the first option we should try. So if you try that and describe the steps you take and what messages you get in the jack-in terminal, maybe we can figure out what goes wrong.

Steph Crown20:09:27

I pressed CTRL + SHIFT + P then clicked on "start or connect to a Clojure repl • I click "start your project with a repl and connect" • I click "deps.edn + Figwheel main" • I check :fig and :build • I click ok This starts up the webpage at localhost:9500.

Steph Crown20:09:20

But I can't use the command in the ide to evaluate expressions.

pez21:09:16

Can you copy the all the contents of the jack-in terminal, and paste it here? I suspect the :build alias can cause problems, but Calva should warn about that, if so. With all the text from the jack-in terminal it will be easier. And if you could paste the :build alias definition as well.