Fork me on GitHub
#clojurescript
<
2018-01-09
>
phronmophobic00:01:40

@sonnyto, I assume the repl runs the compiled javascript in something like (function(){ *compiled cljs code* })();

mfikes00:01:47

@sonnyto My initial hunch is that, in the ClojureScript REPL, when you evaluate a form, it is not being done in the global JavaScript scope.

sonnyto00:01:02

thanks! that works, however I do not understand that solution. what does binding js/eval to geval have that side affect?

sonnyto00:01:13

there's a gap in my understanding of symbol binding

mfikes00:01:55

You can get around this by, for example doing (let [geval js/eval] (geval "function abc(){}"))

mfikes00:01:23

@smith.adriane Yeah, I think you are right. Planck specifically doesn't do that in order to fix, for example https://github.com/mfikes/planck/issues/543 (see the bit at the very bottom of that bug thread)

mfikes00:01:15

As a consequence, in Planck:

cljs.user=> (js/eval "function abc(){return 1;}")
nil
cljs.user=> (js/abc)
1

phronmophobic00:01:36

seems like relying on that behavior is looking for trouble

sonnyto00:01:36

how does binding js/eval to geval fix the problem?

sonnyto00:01:46

geval and js/eval are equivalent right? there must be some side affect going on that i dont understand

mfikes00:01:47

By binding, `" the eval code is not being evaluated by a direct call"

mfikes00:01:30

In short, it is an ECMAScript 5 feature ¯\(ツ)

mfikes00:01:06

Hah. No need to convince me that ClojureScript is sane 🙂

sonnyto00:01:36

🙂 thanks for the response. i'll copy and paste this to the google group just in case someone else runs into same problem

mfikes00:01:11

Yeah, perhaps refer to it as "indirect js/eval for global scope" 🙂

phronmophobic00:01:35

as an aside, it seems doing something like

cljs.user> (def abc (js/eval "function(){}"))
(var cljs.user/abc)
cljs.user> abc
#object[Function "
function () {
}
"]
might be a good option rather than relying on names between the evaled js and the names cljs produces to match

mfikes00:01:32

Well, (js/eval "function(){}") will compile to eval("function(){}"), which is a direct call to eval. The issue is that you don't have much control over the scope that this call is made within, and you may not be able to guarantee that you are running in an ECMAScript 5 VM, so there is probably no real good solution.

phronmophobic00:01:48

i’m not exactly sure what the use case, but the main difference is that the name no longer matters (ie. the variable name abc is on the outside of the eval rather than within the eval)

phronmophobic00:01:02

and you’re no longer depending on how the code within the eval is scoped

phronmophobic00:01:28

and then you don’t have to know the ecmascript 5 vm rules

jvuillermet10:01:42

Hello, I’m trying to make a client side cljs app to discover clj specs from the community. I’d like to be able to get spec from a gist or a textarea and provide a way to generate sample datas from the spec. Looking at Lumo code, I think I have to use cljs/eval-str which I successfully did to eval some trivial code and use it from the rest of the app. I’m now struggling to eval some specs as I can’t figure how to require cljs.spec.alpha. Even looking at the load fn from lumo.repl https://github.com/anmonteiro/lumo/blob/703e6bebc15624b1dd2306f4b1be4bafcce47507/src/cljs/snapshot/lumo/repl.cljs#L1137 I don’t understand what should I do. I think I need to look at load-bundled but I’m not sure because even when I do (cb {:source "" :lang :js) I have an error :`cljs.spec.alpha.def is not a function`. I would assume that cljs spec is already there (bundled) because I have it as a dependency but that’s where I’m lost. Could someone point me to the right direction if any ? Thanks !

jakob13:01:21

Hi 👋 . What input validation library would you recommend? Tried struct (http://funcool.github.io/struct/latest/) but it didn't support nested fields and haven't been updated in 2 years so I thought there might be something better

andre.stylianos13:01:40

probably spec is now the default way to handle those kind of things

jakob13:01:46

Thanks! :thumbsup:

andre.stylianos13:01:57

If validating input forms or similar, then you can use spec + https://github.com/alexanderkiel/phrase to generate the validation messages.

jakob13:01:42

Yes it's for form validation, thanks will look into that one

mfikes14:01:11

@jvuillermet I'd take a look at KLIPSE, which has a mechanism for loading code from a gist

mfikes14:01:14

At its core, you need to properly implement cljs.js/*load-fn*

Macroz16:01:10

hmm should this work in CLJS without anything special? (edn/read-string "#inst \"2017-10-12T13:00:00.000-00:00\"")

thheller16:01:11

depends on which namespace edn is?

thheller16:01:37

(cljs.reader/read-string "#inst \"2017-10-12T13:00:00.000-00:00\"") works

Macroz16:01:26

thanks @thheller it was "wrong"

lilactown21:01:40

I’m confused why I would use the nominal clojurescript compiler vs. lumo vs. shadow-cljs

lilactown21:01:59

the repos don’t explain why I would use them, just that they can build clojurescript code as well

thheller21:01:11

shadow-cljs is a full build tool, it also provides hot code reloading and more dev stuff

thheller21:01:29

so it has a lot more features compared to the base compiler

grav21:01:57

How come, Cljs cannot infer externs with code like this:

(def expo (js/require "expo"))
(expo.Audio.setIsEnabledAsync true)

grav21:01:55

Can I somehow do anything code-wise, instead of adding each call to expo.something to externs.js manually?

dnolen21:01:37

@grav did you try ^js type hint on expo? (also this is probably a defect and should open an issue about it)

grav21:01:33

@dnolen Trying that out now

lilactown21:01:52

@thheller are there any breakdowns of shadow-cljs vs cljs + figwheel?

lilactown21:01:26

I’m trying to figure out what to standardize on for my team and I’m having trouble finding out what features these different compilers/build tools have and what their value propositions are

thheller21:01:27

shadow-cljs does everything figwheel does and more

thheller21:01:29

I’m not aware of any actual comparisons. I can’t do one myself since I never used figwheel 😛

dnolen21:01:25

@lilactown lumo is bootstrapped so if you need/want to avoid JVM for some reason (less users but it’s a growing use case)

dnolen21:01:59

ClojureScript compiler is at the bottom of everyone’s efforts, bootstrapped or whatever

grav21:01:34

@dnolen No, ^js doesn’t seem to make a difference. I did at some point see a WARNING: target/expo/inferred_externs.js:53: WARNING - name expo is not defined in the externs, but I cannot seem to reproduce it.

juhoteperi21:01:42

@thheller Does shadow-cljs provide HUD similar to Figwheel and Boot-reload (a view on the browser to display warnings and errors)?

thheller22:01:10

hud yes but very ugly, still need to work on that

dnolen22:01:17

@grav hrm I don’t know then

juhoteperi22:01:27

@thheller Oh, I see it now, warnings are displayed but errors not

thheller22:01:58

I personally never liked the hud since I already see errors/warnings in cursive

thheller22:01:10

looking at the browser for those feels kinda weird

juhoteperi22:01:07

Emacs/vim are still major editors and those don't have as good (... or any) static analysis. Many people probably keep the console open for errors, but HUD allows me to focus on just browser + vim.

lilactown22:01:40

yeah, most of our team is using Atom. I’m on Emacs. so a HUD is fairly useful